Kez*_*des 2 java serialization
我有一个Arraylist,我想保存在一个文件中,以便在应用程序中使用另一次,我已经阅读了几个我可以使用此代码执行此操作的地方,但它不起作用,它会在之后返回错误打印出3:
private void savegame(){
try {System.out.println("1");
FileOutputStream preout = new FileOutputStream(new File("savedgame.ser"));
System.out.println("2");
ObjectOutputStream out = new ObjectOutputStream(preout);
System.out.println("3");
out.writeObject(kortene);
System.out.println("4");
out.close();
System.out.println("5");
preout.close();
System.out.println("6");
output = new FileWriter(new File("saved game settings.txt"));
System.out.println("7");
output.write(Indstillinger.BilledeMappe+"\n"+Indstillinger.AntalKort+
"\n"+Indstillinger.AntalSpillere+"\n"+clicks+"\n"+Score);
System.out.println("8");
output.close();
System.out.println("game save success");
}catch (Exception e) {
System.out.println("game save failed");
}
Run Code Online (Sandbox Code Playgroud)
和"kortene"是这样创建的ArrayList:
public static ArrayList<Kort> kortene = new ArrayList<Kort>();
Run Code Online (Sandbox Code Playgroud)
和Kort是我制作的一个类,但这与我假设的这个问题无关.
我得到的错误是:java.io.NotSerializableException:java.awt.image.BufferedImage
但我没有BufferedImage,我只是在每个类中都有一个正常的图像......
相信编译器:如果它说它BufferedImage用于将图像保存在内存中,那就是真的.javadocs说它不是Serializable:
http://download.oracle.com/javase/1.5.0/docs/api/java/awt/image/BufferedImage.html
您可以将图像标记为,transient并在以后反序列化时从文件系统重新初始化它们.放手一搏.
| 归档时间: |
|
| 查看次数: |
1733 次 |
| 最近记录: |