Android中的序列化 [英] Serialization in Android
本文介绍了Android中的序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 android 中序列化绘制和路径.当我将一个对象写入 Objectoutputstream 时,Notserializabale 异常被触发.我也在 serializabale 类中重写了 writeObject() 方法.
I am trying to Serialize paint and path in android. When I am write a object to Objectoutputstream the Notserializabale exception is fired. I am also overwite a writeObject() methods in serializabale class .
这是代码.
public class msgContainar implements Serializable
{
/**
*
*/
public msgContainar()
{
}
private static final long serialVersionUID = 1L;
private Path pathStack;
private Paint paintStack;
public Path getPathStack()
{
return pathStack;
}
public void setPathStack(Path pathStack)
{
this.pathStack = pathStack;
}
public Paint getPaintStack()
{
return paintStack;
}
public void setPaintStack(Paint paintStack)
{
this.paintStack = paintStack;
}
private void writeObject(ObjectOutputStream out) throws IOException
{
try
{
Paint p=new Paint();
p.set(paintStack);
Path path=new Path();
path.addPath(pathStack);
out.writeObject(path);
out.writeObject(p);
}catch (Exception e)
{
Log.e("err",""+e);
}
}
private void readObject(ObjectInputStream in) throws IOException{
try{
Paint p=new Paint();
p=paintStack;
Path path=new Path();
path=pathStack;
}catch (Exception e) {
Log.e("err",""+e);
}
}
}
推荐答案
Path 和 Paint 都没有实现 Serializable 接口.要解决此问题,您可以创建自己的自定义子类来扩展 Path
和 Paint
并实现 Serializable
.
Neither Path nor Paint implements the Serializable interface. To work around this, you can create your own custom subclasses that extend Path
and Paint
and implement Serializable
.
这篇关于Android中的序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文