问题
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
回答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
来源:https://stackoverflow.com/questions/4867582/parcelable-encounteredclassnotfoundexception-reading-a-serializable-object