I already did that... it gives me this error:
"java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: Player"
here's my serialization class:
Code:
import java.util.*;
import java.io.*;
public class LoadSave extends Player implements Serializable
{
private File filename = new File("sList.sav");
private HashMap list;
/**
*
*/
public LoadSave(HashMap list)
{
this.list = list;
}
/**
*
*/
public boolean load()
{
if(filename.exists())
try {
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(filename));
list = (HashMap)in.readObject();
in.close();
}
catch(ClassNotFoundException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
catch (NotSerializableException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
catch (FileNotFoundException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
catch(IOException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
return true;
}
public boolean save()
{
try {
System.out.println("Saving Character List");
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
out.writeObject(list);
out.close();
}
catch (NotSerializableException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
catch (FileNotFoundException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
catch(IOException e) {
if (PlayXandersGame.DEBUG)
System.out.println(e);
return false;
}
return true;
}
}
Bookmarks