【发布时间】:2013-08-20 12:03:47
【问题描述】:
private Map<String, List<DrawPath>> savedPath= new LinkedHashMap<String, List<DrawPath>>();
我想将此“savedPath”写入文件,但抛出 IOException:
public static class DrawPath implements Serializable{
/**
*
*/
public static final long serialVersionUID = 1L;
public Path path;
public Paint paint;
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(sdFile));
out.writeObject(savedPath); // throws IOExcption
如果更改为Map<String, String>,它会成功运行,它与我的自定义 DrawPath 类有关吗?如何将此对象写入文件成功?谢谢
【问题讨论】:
-
请将您的 Logcat 错误日志连同您的问题一起发布。
-
它被 try { out.writeObject(savedPath); 捕获} catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); }
-
嗯,控制台选项卡附近有一个logcat选项卡。当应用程序崩溃时,您捕获的错误会打印在那里。请在应用程序崩溃时找到您的 logcat 中的所有错误代码和字符串,并将其粘贴到您的问题中。
-
你知道我应该保存画图吗?或者除了 DrawPath 类之外的其他对象如何 Serializable ?
标签: android file object serializable objectoutputstream