TheGrintch Posted January 25, 2011 Share Posted January 25, 2011 Bonjour à tous, Pour des besoin d'animation, je dois regrouper des views, au seins d'une map. private Map<ImageView, List<View>> mListView = new TreeMap<ImageView, List<View>>(); Seulement, lors de la première insertion tout ce passe bien, mais lors de la seconde, j'ai une exception qui se déclenche (java.lang.ClassCastException: android.widget.ImageView): View imageView1 = findViewById(R.id.imageView1); this.mListView.put((ImageView)imageView1, null); List<View> arrView = new ArrayList<View>(); arrView.add(findViewById(R.id.bouton1)); View imageView2 = findViewById(R.id.imageView2); this.mListView.put((ImageView)imageView2, arrView); Juste pour préciser, imageView2 n'est pas null lors de l'insertion (Vérification en debug). Est-ce que vous avez une idée, sur ce problème ? Merci. Link to comment Share on other sites More sharing options...
chpil Posted January 25, 2011 Share Posted January 25, 2011 imageView2 est-elle bien une ImageView ? Quel est le contenu XML du layout qui correspond ? Link to comment Share on other sites More sharing options...
TheGrintch Posted January 25, 2011 Author Share Posted January 25, 2011 Voici le XML, en trois parties: Main.xml: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/conteneur" android:layout_width="fill_parent" android:layout_height="fill_parent"> <include android:id="@+id/notelist" layout="@layout/premier_ecran"/> <include android:id="@+id/notelist" layout="@layout/deuxieme_ecran"/> </FrameLayout> premier_ecran.xml: <RelativeLayout android:id="@+id/premier_ecran_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/imageView1" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image1"/> </RelativeLayout> deuxieme_ecran.xml: <RelativeLayout android:id="@+id/deuxieme_ecran_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <RelativeLayout android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image2"/> <Button android:id="@+id/bouton1" android:layout_marginLeft="20dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Test"/> </RelativeLayout> </RelativeLayout> Link to comment Share on other sites More sharing options...
chpil Posted January 25, 2011 Share Posted January 25, 2011 Bon, l'erreur doit être ailleurs, imageView2 est bien une ImageView Peux-tu préciser sur quelle ligne se déclenche l'exception ? quel la trace dans le logcat ? Link to comment Share on other sites More sharing options...
TheGrintch Posted January 25, 2011 Author Share Posted January 25, 2011 Alors, le logcat n'est pas explicite: logcat: 01-25 12:22:59.313: DEBUG/dalvikvm(17531): threadid=1: still suspended after undo (sc=1 dc=1 s=Y) 01-25 12:23:03.391: DEBUG/dalvikvm(17531): GC_EXTERNAL_ALLOC freed 701 objects / 57120 bytes in 77ms 01-25 12:23:05.270: DEBUG/dalvikvm(3032): GC_EXPLICIT freed 617 objects / 37536 bytes in 153ms 01-25 12:23:06.324: WARN/ActivityManager(2948): Activity idle timeout for HistoryRecord{48de4008 android.flip.test/.Flip3d} Et pour la ligne qui retourne l'exception c'est: this.mListView.put((ImageView)imageView2, arrView); Link to comment Share on other sites More sharing options...
chpil Posted January 25, 2011 Share Posted January 25, 2011 Effectivement, le logcat n'aide pas... D'après la ligne de code, c'est donc qu'il n'arrive pas à caster imageView2 en une ImageView. Puisque tu vois au debugger que imageView2 n'est pas null, tu peux aussi voir le type réel de l'instance. Est-ce bien un objet de type ImageView ??? Link to comment Share on other sites More sharing options...
TheGrintch Posted January 25, 2011 Author Share Posted January 25, 2011 Oui, c'est bien une ImageView :) J'ai testé ce petit bout de code: ImageView tmp1 = new ImageView(this); ImageView tmp2 = new ImageView(this); ImageView tmp3 = new ImageView(this); ImageView tmp4 = new ImageView(this); this.mListView.put(tmp1, null); this.mListView.put(tmp2, null); //Exception thrown this.mListView.put(tmp3, null); this.mListView.put(tmp4, null); Mais ça fait la même chose que sur mon code. à la deuxième ligne, exception. Une idée ? Link to comment Share on other sites More sharing options...
TheGrintch Posted January 25, 2011 Author Share Posted January 25, 2011 J'ai résolu mon problème: utilisé une hashMap à la place d'une TreeMap: //Map<ImageView, List<View>> mList = new TreeMap<ImageView, List<View>>(); Map<ImageView, List<View>> mList = new HashMap<ImageView, List<View>>(); PS: Je ne peux pas mettre résolu tout seul. En tout cas merci d'avoir pris du temps pour me répondre ^^ Link to comment Share on other sites More sharing options...
chpil Posted January 25, 2011 Share Posted January 25, 2011 Le problème n'est pas le même qu'initialement. Mais, effectivement, un TreeMap n'accepte pas de valeurs null, au contraire d'une HashMap Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.