保存我的序列化类,该类尚未序列化对象(如 Rect)
当活动调用 onDestroy() 时,我试图保存序列化对象,但是当我尝试使用 ObjectOutputStream 写入对象时,会引发 java.io.NotSerializedExeption。
你能帮我一下吗?谢谢
I'm trying to save my Serialized object when the activity calls the onDestroy() but when i try to write my object using ObjectOutputStream a java.io.NotSerializableExeption is thrown.
Can you please help me. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题并制作了这个类来帮助序列化:
I encountered same problem and made this class to help the serialization:
如果您的对象映射包含不可序列化的对象,VM 将查找无参数构造函数,以便创建具有默认值的对象并继续。当它不能时,它会抛出此异常。最重要的是,对象图中引用的每个对象都必须:
您没有提供足够的细节让我进一步了解,但我无论如何也无法为您写出来?一般来说,您可以从不可序列化的类派生或包装它们并提供必要的功能。只要每个成员都满足我列出的条件,就不应抛出异常。
If your object map contains an unserializable object the VM looks for a no argument constructor so as to make an object with the default values and move on. It throws this exception when it can't. The bottom line is that each and every object referenced in your object graph must either:
You do not provide enough specifics for me to go further, but I can't write it for you anyway? In general, you can derive from the unserializable classes or wrap them and provide the necessary functionality. So long as each member meets the conditions I listed, no exception should be thrown.
您需要确保该类实现 java.io.Serialized 接口。还可以考虑使用 Bundles 并将数据保存在
onSaveInstanceState
中。有关数据存储的更多信息,请参阅此开发指南主题。You need to ensure that the class implements the
java.io.Serializable
interface. Also consider using Bundles instead and saving your data inonSaveInstanceState
. For more on data storage, see this dev guide topic.