Parcelable encounteredClassNotFoundException读取序列化对象 [英] Parcelable encounteredClassNotFoundException reading a Serializable object
问题描述
我实现了实现Serializable对象的类。
公共类SaveMe实现Serializable {
私有静态最后的serialVersionUID长1L =;
私人字符串someValue1;
私人字符串someValue2;
}
但每当我试图以捆绑使用它,我得到这个异常:
Parcelable encounteredClassNotFoundException读取序列化对象
在android.os.Parcel.readSerializable(Parcel.java:1951)
在android.os.Parcel.readValue(Parcel.java:1822)
在android.os.Parcel.readMapInternal(Parcel.java:2008)
在android.os.Bundle.unparcel(Bundle.java:208)
在android.os.Bundle.getString(Bundle.java:1034)
我在做什么错了?
修改
唔...使用Parcelable类似的问题时:
解编班时未找到
我相信你可能会运行到类加载器的问题。你需要你读序列化对象了出来之前调用setClassLoader()的捆绑。
请确保你调用 setClassLoader(SaveMe.class.getClassLoader())
前从包读取。
如果编译时则确保一流的缺失在目标应用为潮湿建议编译器无法找到SaveMe。
看到这个答案的详细信息:
<一href=\"http://stackoverflow.com/questions/13421582/parcelable-inside-bundle-which-is-added-to-parcel/13575442#13575442\">Parcelable里面包这是添加到包裹
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
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
这篇关于Parcelable encounteredClassNotFoundException读取序列化对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!