Android的 - 问题与Serializable接口 [英] Android - Problem with the Serializable interface
问题描述
我一直在使用序列化
接口将对象传递从一个活动到另一个。我使用 putExtra
在发送方和 getSerializable
在接收端。一切工作正常,但我收到(首次)以下的错误报告:
I have been using the Serializable
interface to pass an object from one activity to another. I am using putExtra
on the sender side and getSerializable
on the receiver side. Everything works fine but I have received (for the first time) the following error report:
了java.lang.RuntimeException:Parcelable遇到IOException异常读数
Serializable对象
java.lang.RuntimeException: Parcelable encountered IOException reading a Serializable object
我不明白,因为我使用 getSerializable
,而不是 getParcelable
为什么这个异常已经产生。
I don't understand why this exception has been generated since I am using getSerializable
and not getParcelable
.
我知道我应该实现,而不是因为它已经为Android专门设计(这是我最终会做)的 Parcelable
接口,但我想知道为什么我收到此错误。
I know that I should implement the Parcelable
interface instead because it has been designed specifically for Android (and that's what I will end up doing) but I want to understand why I am getting this error.
谢谢!
推荐答案
Parcelable
在这个错误被提及,因为意图
您从一个活动
到另一个发送有一个捆绑
内,本捆绑
是 Parcelable
。当你调用 Intent.putExtra()
这个额外添加到里面的捆绑
。当意图
的活动之间传递的捆绑
转换和从字节数组,和你的序列化
对象。
Parcelable
is mentioned in this error because an Intent
you send from one Activity
to another has a Bundle
inside and this Bundle
is Parcelable
. When you call Intent.putExtra()
this extra is added to the inner Bundle
. When Intent
is passed between activities its Bundle
is converted to and from a byte array and so is your Serializable
object.
但我不知道为什么这个错误发生时。也许是因为在的writeObject()
/ 的readObject()
实施
But I don't know why this error occurs. Maybe it's because of some bug in writeObject()
/readObject()
implementation.
这篇关于Android的 - 问题与Serializable接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!