我已经实现了一个实现可序列化对象的类。
public class SaveMe implements Serializable {
private static final long serialVersionUID = 1L;
private String someValue1;
private String someValue2;
}
但每当我尝试在 Bundle 中使用它时,我都会收到此异常:
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)
我究竟做错了什么?
Edit
嗯...使用 Parcelable 时出现类似问题:
Class not found when unmarshalling
我相信您可能会遇到类加载器问题。在从 Bundle 中读取序列化对象之前,您需要在 Bundle 上调用 setClassLoader()。
确保你打电话setClassLoader(SaveMe.class.getClassLoader())
在从包中读取之前。
如果编译器在编译时找不到 SaveMe,那么可以肯定目标应用程序中缺少该类Damp https://stackoverflow.com/users/525623/damp建议。
请参阅此答案了解更多详细信息:添加到 Parcel 的可打包内部捆绑包 https://stackoverflow.com/questions/13421582/parcelable-inside-bundle-which-is-added-to-parcel/13575442#13575442
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)