【发布时间】:2015-07-26 08:37:41
【问题描述】:
所以我有一个名为 World 的类:
public class World implements Serializable {
private int dx;
private int dy;
private int x;
private int y;
private Path path;
public ImageIcon image;
public ArrayList<Location> locations;
在将对象添加到 ArrayList<Location> locations; 之前,我正在对其进行序列化和反序列化处理。
现在当我尝试运行序列化时
try {
FileOutputStream fos = new FileOutputStream(Main.board.worldpath.toString());
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(Main.board.world.image);
oos.writeObject(Main.board.world);
oos.close();
}catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
它在oos.writeObject(Main.board.world);这一行抛出java.io.NotSerializableException: sun.nio.fs.WindowsPath
Location 类也是可序列化的:
public class Location implements Serializable {
public int x;
public int y;
public String name;
public String desc;
我不知道为什么它会说它不可序列化,那么序列化 ArrayLists 有什么特别之处吗?
【问题讨论】:
标签: java serialization arraylist