Bonjour,

J'essai de faire passer un objet dans un Bundle avec une propriété de type Drawable mais une exception est levée :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
06-20 20:29:46.961: E/AndroidRuntime(1731): FATAL EXCEPTION: main
06-20 20:29:46.961: E/AndroidRuntime(1731): java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.test.android.appli/fr.test.android.appli.MainActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: 
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Looper.loop(Looper.java:137)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.ActivityThread.main(ActivityThread.java:5039)
06-20 20:29:46.961: E/AndroidRuntime(1731): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 20:29:46.961: E/AndroidRuntime(1731): at java.lang.reflect.Method.invoke(Method.java:511)
06-20 20:29:46.961: E/AndroidRuntime(1731): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-20 20:29:46.961: E/AndroidRuntime(1731): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-20 20:29:46.961: E/AndroidRuntime(1731): at dalvik.system.NativeStart.main(Native Method)
06-20 20:29:46.961: E/AndroidRuntime(1731): Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: 
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Parcel.readParcelable(Parcel.java:2077)
06-20 20:29:46.961: E/AndroidRuntime(1731): at fr.test.android.appli.rss.weather.ObjectWithDrawable.<init>(Weather.java:54)
06-20 20:29:46.961: E/AndroidRuntime(1731): at fr.test.android.appli.rss.weather.ObjectWithDrawable$1.createFromParcel(Weather.java:91)
06-20 20:29:46.961: E/AndroidRuntime(1731): at fr.test.android.appli.rss.weather.ObjectWithDrawable$1.createFromParcel(Weather.java:1)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Parcel.readParcelable(Parcel.java:2103)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Parcel.readValue(Parcel.java:1965)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Parcel.readMapInternal(Parcel.java:2226)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Bundle.unparcel(Bundle.java:223)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.os.Bundle.getParcelable(Bundle.java:1165)
06-20 20:29:46.961: E/AndroidRuntime(1731): at fr.test.android.appli.MainActivity.onCreate(MainActivity.java:83)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.Activity.performCreate(Activity.java:5104)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-20 20:29:46.961: E/AndroidRuntime(1731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
Le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class ObjectWithDrawable implements Parcelable {
...
public Drawable icon;
...
public Weather(Parcel in){
...
        this.icon=in.readParcelable(Drawable.class.getClass().getClassLoader());
        ...
        }
 
public void writeToParcel(Parcel dest, int flags) {
        ...
        Bitmap bitmap = (Bitmap) ((BitmapDrawable) icon).getBitmap();
        dest.writeParcelable(bitmap,flags);
}
}
J'ai vu pas mal de sujet mais rien de concluant.

Merci d'avance pour votre aide.