gpt4 book ai didi

java - Android 中的序列化

转载 作者:行者123 更新时间:2023-12-01 15:37:35 27 4
gpt4 key购买 nike

我正在尝试在 android 中序列化绘图和路径。当我将对象写入 Objectoutputstream 时,会引发 Notserializabale 异常。我还覆盖了serializabale类中的writeObject()方法。

这是代码。

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界面。要解决此问题,您可以创建自己的自定义子类来扩展 PathPaint 并实现 Serialized

关于java - Android 中的序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8641434/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com