Parcelable encounteredClassNotFoundException reading a Serializable object

╄→尐↘猪︶ㄣ 提交于 2019-12-08 05:31:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!