2012-06-25 15 views
57

मैं इस सूची को मेरी सूचीदृश्य टेम्पलेट पर ठीक नहीं कर सकता: मुझे अपनी पोस्ट के शीर्षक में त्रुटि है, लेकिन मैं टेक्स्टव्यू पर छविदृश्य नहीं डालेगा।एंड्रॉइड: java.lang.ClassCastException: android.widget.imageView को android.widget.textView पर नहीं डाला जा सकता है

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="200dip" 
android:layout_weight="1" 
android:paddingBottom="10dip" > 

<TextView 
    android:id="@+id/mq" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="Metri quadri" 
    android:textColor="#33b5e5" 
    android:textSize="14sp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/citta" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/mq" 
    android:layout_alignBottom="@+id/mq" 
    android:layout_centerHorizontal="true" 
    android:text="Citta" 
    android:textColor="#33b5e5" 
    android:textSize="14sp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/prezzo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Prezzo" 
    android:textColor="#e1e1e1" 
    android:textSize="14sp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/nome" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:padding="5dip" 
    android:scrollHorizontally="true" 
    android:singleLine="true" 
    android:text="@string/testolungo" 
    android:textColor="#e1e1e1" 
    android:textSize="20sp" 
    android:textStyle="bold" /> 

<ImageView 
    android:id="@+id/foto" 
    android:layout_width="80dip" 
    android:layout_height="60dip" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:contentDescription="Release" 
    android:padding="5dip" 
    android:scaleType="centerCrop" 
    android:src="@drawable/stub" /> 

<TextView 
    android:id="@+id/descsplash" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="Small Text" 
    android:textSize="16sp" 
    android:textStyle="italic" /> 

</RelativeLayout> 

जावा कोड के लिए त्रुटि मेरी फाइल है, जहां मैं आवंटित TextView MQ के लिए TextView आईडी की लाइन 58 पर है::

View vi=convertView; 
    if(convertView==null) 
    vi = inflater.inflate(R.layout.listlay, null); 
    TextView nome=(TextView)vi.findViewById(R.id.nome); 
    TextView mq=(TextView)vi.findViewById(R.id.mq); // here's the error (???) 
    TextView citta=(TextView)vi.findViewById(R.id.citta); 
    TextView prezzo=(TextView)vi.findViewById(R.id.prezzo); 
    ImageView image=(ImageView)vi.findViewById(R.id.foto); 
    TextView descrizione = (TextView)vi.findViewById(R.id.descsplash); 
    nome.setText(data.get(position).getNome()); 
    mq.setText(data.get(position).getMetriQuadri()); 
    citta.setText(data.get(position).getCitta()); 
    prezzo.setText(data.get(position).getPrezzo()); 
    descrizione.setText(data.get(position).getDescrizione()); 
    imageLoader.DisplayImage(data.get(position).getForoUrl(), image); 

और यहाँ है logcat:

यहाँ मेरी कोड है

06-25 16:08:32.497: D/Debug(14642): Prendo Textview MQ
06-25 16:08:32.497: D/AndroidRuntime(14642): Shutting down VM
06-25 16:08:32.497: W/dalvikvm(14642): threadid=1: thread exiting with uncaught exception (group=0x40a561f8)
06-25 16:08:32.497: E/AndroidRuntime(14642): FATAL EXCEPTION: main
06-25 16:08:32.497: E/AndroidRuntime(14642): java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView
06-25 16:08:32.497: E/AndroidRuntime(14642): at com.prova.listview.LazyAdapter.getView(LazyAdapter.java:58)

क्या कोई जानता है कि मैं इस समस्या को कैसे ठीक कर सकता हूं?

+7

सही लगता हो जाएगा। बस अपनी परियोजना को साफ करने की कोशिश करें। – Praveenkumar

+0

क्या आप catlog पोस्ट कर सकते हैं? एक साफ हो सकता है जिसे आपको @ एसपीके की आवश्यकता होती है – MikeIsrael

+0

06-25 16: 08: 32.497: डी/डीबग (14642): प्रीडो टेक्स्टव्यू एमक्यू 06-25 16: 08: 32.497: डी/एंड्रॉइड रनटाइम (14642): नीचे बंद करना वीएम 06-25 16:08:32।4 9 7: डब्ल्यू/दल्विकविक (14642): थ्रेडिड = 1: बिना अपवाद के समूह से बाहर निकलने वाला थ्रेड (समूह = 0x40a561f8) 06-25 16: 08: 32.497: ई/एंड्रॉइड रनटाइम (14642): अंतिम अपवाद: मुख्य 06-25 16: 08: 32.497: ई/एंड्रॉइड रनटाइम (14642): java.lang.ClassCastException: android.widget.ImageView को android.widget पर नहीं डाला जा सकता है। टेक्स्टव्यू 06-25 16: 08: 32.497: ई/एंड्रॉइड रनटाइम (14642): \t पर com.prova.listview.LazyAdapter.getView (LazyAdapter.java:58) – Release

उत्तर

179

ग्रहण हर समय आपके संसाधनों को गड़बड़ कर देता है। इससे कुछ अजीब व्यवहार होते हैं जैसे स्ट्रिंग और छवियों को आपके ऐप पर बदल दिया जाता है, और अधिक सामान्यतः क्लासएक्सएक्सप्शन (ओं), जो तब होता है जब ग्रहण आपके दृश्यों के आसपास बदलता है।

कि समस्या का कुछ समाधान:

अपनी परियोजना को साफ करें।

एक एक्सएमएल लेआउट फ़ाइल संशोधित करें और सहेजें।

अपनी आर फ़ाइल हटाएं। (चिंता न करें यह स्वचालित रूप से फिर से उत्पन्न हो जाएगा)।

असल में ऐसा कुछ भी जो आपकी परियोजना को पुनर्निर्माण और आर फ़ाइल को पुन: उत्पन्न करता है।

+4

मैंने अपनी आर फाइल हटा दी। अब सब ठीक काम करता है। समस्या सुलझ गयी। आपका बहुत बहुत धन्यवाद! – Release

+3

एक क्लासिक स्थिति जब परियोजना> स्वच्छ बचाव के लिए आता है ... –

+0

इसके लिए धन्यवाद। मैं इस समस्या के खिलाफ पूरी सुबह लड़ रहा था। (आपके लिए +1) – Luixv

3

बस अपनी परियोजना को साफ करें और सब ठीक हो जाएगा।

+3

इससे मेरी मदद नहीं हुई, मुझे दृश्य की आईडी बदलनी पड़ी और पुन: संकलित करना पड़ा – MartinC

1

प्रारंभ में, मैं हो रही थी त्रुटि:

TextView : android:id="@+id/add_expected_seekbarvalue"

SeekBar : android:id="@+id/add_expected_seekbar"

एक फिक्स रूप में, मैं

TextView : android:id="@+id/add_expected_valueseekbar"

भी साफ रूप TextView के लिए id नाम और अन्य तकनीकें डी काम नहीं करते लेकिन अंत में आईडी को नाम बदलने के लिए एक आकर्षण की तरह काम किया।

1

कभी-कभी इस समस्या से पता चलता है क्योंकि हम imageView बनाया लेकिन इस

<ImageView 
     android:id="@+id/iv_thumb" 
     android:layout_width="50dip" 
     android:layout_height="50dip" 
     /> 

    holder.imageView = (ImageButton) convertView.findViewById(R.id.iv_thumb); 

हम imageView घोषित लेकिन इस कारण से भी इस समस्या का सामना किया है के लिए ImageButton लिए डाली, है की तरह के रूप में छवि बटन के साथ कास्ट किया है।

0

सिर्फ अपनी परियोजना ... मैं भी इसी तरह की समस्या के माध्यम से चला .. स्वच्छ परियोजना सब कुछ के बाद साफ fine..best भाग्य

संबंधित मुद्दे