Parcelable encounteredClassNotFoundException reading a Serializable object
Asked Answered
A

1

4

I've implemented a class that implements Serializable object.

public class SaveMe implements Serializable {
    private static final long serialVersionUID = 1L;
    private String someValue1;
    private String someValue2;
} 

But whenever I try to use it in a Bundle, I get this exception:

 Parcelable encounteredClassNotFoundException reading a Serializable object
     at android.os.Parcel.readSerializable(Parcel.java:1951)
     at android.os.Parcel.readValue(Parcel.java:1822)
     at android.os.Parcel.readMapInternal(Parcel.java:2008)
     at android.os.Bundle.unparcel(Bundle.java:208)
     at android.os.Bundle.getString(Bundle.java:1034)

What am I doing wrong?

Edit

Hm... Similar issue when using Parcelable:

Class not found when unmarshalling
Accolade answered 1/2, 2011 at 20:25 Comment(3)
Can you show the method call that causes the exception? I've had issues with serializable as well...Encephalon
actually, it is b.putSerializable("savedinstance", new SaveMe()) where b is a Bundle object. Then it is called implicitly when bundle gets restored. Actually, it is restored from another application. Maybe this is an issue?Accolade
If your other app doesn't know the class SaveMe that would probably be the case.Encephalon
H
1

I believe you may be running into class loader issues. You need to call setClassLoader() on the Bundle before you read serialized objects out of them.

Make sure you call setClassLoader(SaveMe.class.getClassLoader()) before reading from the bundle.

If the compiler cannot find SaveMe when compiling then for sure that class is missing in the target application as Damp suggested.

See this answer for more details: Parcelable inside bundle which is added to Parcel

Hyperaemia answered 9/12, 2013 at 4:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.