android - java.lang.RuntimeException: Parcelable encountered IOException writing serializable
问题描述
I have an arraylist
that i want to send from 1 activity to another, I am using serializable but end up getting following error message.
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.app...)
I have also reviewed some question regarding this on SO
, most of them saying that all classes defined inside your Serialized
class should also implement Serializable
, but here Path
, 'RectF', Matrix
, are not my classes, they are android classes, and i can't implement Serializable
in these classes.
This is how i am sending array list from 1 activity to another.
Intent intent= new Intent(MainActivity.this, DetailsActivity.class);
Bundle bundle= new Bundle();
bundle.putSerializable("PATH_LIST", pathsList);
bundle.putString("FILE_NAME", fileName);
intent.putExtras(bundle);
startActivity(intent);
and this is my class.
public class TData implements Serializable {
Matrix originalMatrix;
public Path path;
PointF position;
private TData attachedPathData;
public void setAttachedPathData(TData pathData){
attachedPathData = pathData;
}
public TData getAttachedPathData(){
return attachedPathData;
}
public TData(){
}
public TData(Path path, PointF position, String id, String fillColor, String strokeColor){
this.path = path;
this.position = position;
this.id = id;
this.fillColor = fillColor;
this.strokeColor = strokeColor;
}
public void Scale(float scaleX, float scaleY){
this.scaleX = scaleX;
this.scaleY = scaleY;
Matrix scaleMatrix = new Matrix();
RectF rectF = new RectF();
path.computeBounds(rectF, true);
scaleMatrix.setScale(scaleX,scaleY);
path.transform(scaleMatrix);
Matrix mat = new Matrix();
path.computeBounds(rf, true);
Region r = new Region();
}
}
解决方案
这里的 Path,'RectF',Matrix,不是我的类,它们是 android 类,我无法在这些类中实现 Serializable..
然后在类中没有他们的字段Serializable
。
任何一个:
这里没有单独的活动,而是做一些其他事情(例如,一个活动和两个片段),以避免需要
Intent
, 或不要在活动之间传递这些数据,而是使用不同的应用程序架构(例如,数据不由任何一个活动保存,而是由两个活动可以与之通信的存储库保存),或者
创建一些您可以制作的数据结构
Parceable
or ,您可以从中使用Serializable
所需的类重建模型对象,并将该Parcelable
/Serializable
数据结构传递给Intent
TData
推荐阅读
- metadata - Snowflake 真正维护文件加载历史记录多久?
- cross-validation - 如何使用 CV 训练模型?
- javascript - Chrome 如何确定 input[type="date"] 格式?
- git - 使用 github 之类的远程存储库与在 google 驱动器之类的共享驱动器上使用 git 有什么优势?
- python - 如何通过考虑 Python 中的标准来创建 NumPy 数组的子元素?
- r - 将 python POST 请求转换为 R httr POST 请求
- reactjs - coreui自定义组件及手机版logo
- fetch-api - 无法在数据库中发布数据。在后端端口(1337)时使用端口(8080)。使用 no-cors 来避免访问源问题。一直收到415错误
- wordpress - Woocommerce 手动免税
- common-lisp - 为什么 SBCL(或一般的 Common lisp?)不喜欢我的循环?