Is that functionality working ? Or Am doing something wrong (never used salvable before :P) ?
The data was saved using the writeSavableArrayList ok, the file is in the diretory with data, but the load gets this error :
java.lang.InstantiationException: mygame.ProfileLoader$Profile
at java.lang.Class.newInstance(Class.java:359)
at com.jme3.export.SavableClassUtil.fromName(SavableClassUtil.java:171)
at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:335)
at com.jme3.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:483)
at com.jme3.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:471)
at com.jme3.export.binary.BinaryInputCapsule.readSavableArrayList(BinaryInputCapsule.java:587)
at mygame.ProfileLoader.read(ProfileLoader.java:312)
at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:344)
at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:242)
at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:125)
at jme3tools.savegame.SaveGame.loadGame(SaveGame.java:184)
at jme3tools.savegame.SaveGame.loadGame(SaveGame.java:128)
at mygame.ProfileLoader.loadData(ProfileLoader.java:149)
at mygame.Main.simpleInitApp(Main.java:135)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)
I already tried to remove the file and re-create, same results.
Any tip on what should be the cause ?
Some code :
public class ProfileLoader implements Savable {
...
public class Profile implements Cloneable,Savable {
String name = "";
...
public void write(JmeExporter ex) throws IOException {
OutputCapsule capsule = ex.getCapsule(this);
capsule.write(name,"name", "Default");
...
}
public void read(JmeImporter im) throws IOException {
InputCapsule capsule = im.getCapsule(this);
name = capsule.readString("name", "Default");
...
}
}
public ArrayList<ProfileLoader.Profile> profileList = new ArrayList<ProfileLoader.Profile>();
...
public void saveData() {
try { SaveGame.saveGame("profiles", "profiles", Main.profile); } catch (Exception except) {
System.out.println(except.toString());
except.printStackTrace();
}
};
public void loadData() {
Main.profile=null;
try { Main.profile = (ProfileLoader) SaveGame.loadGame("profiles", "profiles"); } catch (Exception except) {
System.out.println(except.toString());
except.printStackTrace();
}
if(Main.profile==null) Main.profile = new ProfileLoader();
}
public void write(JmeExporter ex) throws IOException {
OutputCapsule capsule = ex.getCapsule(this); //http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:save_and_load
capsule.writeSavableArrayList(profileList, "profilelist", new ArrayList<ProfileLoader.Profile>());
}
public void read(JmeImporter im) throws IOException {
InputCapsule capsule = im.getCapsule(this);
profileList = capsule.readSavableArrayList("profilelist", new ArrayList<ProfileLoader.Profile>());
}
}