Hello everyone,
I’ve implemented saving and loading for my game, but I’m getting this exception:
> java.lang.ClassCastException: com.jme3.export.binary.BinaryInputCapsule$ID cannot be cast to java.lang.Integer
at com.jme3.export.binary.BinaryInputCapsule.readInt(BinaryInputCapsule.java:401) at de.rbgs.steel_builds.World.World.read(World.java:1012) at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:342) 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 de.rbgs.steel_builds.Main.GameStates.GameState.init(GameState.java:187) at de.rbgs.steel_builds.Main.GameStates.GenericState.initialize(GenericState.java:67) at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251) at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281) at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236) at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151) at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232) at java.lang.Thread.run(Thread.java:745)
I’m sure this should work, here are the saving and loading methods of World.class:
@Override
public void write(JmeExporter ex) throws IOException
{
OutputCapsule out = ex.getCapsule(this);
out.write(mapSize, "mapSize", -1);
out.write(height, "height", -1);
for(int i = 0; i < mapSize; i++)
{
for(int j = 0; j < mapSize; j++)
{
for(int k = 0; k < height; k++)
{
out.write(terrain[i][j][k], "terrain" + i + j + k, null);
}
}
}
out.write(buildings.size(), "buildingsAmount", -1);
for(int i = 0; i < buildings.size(); i++)
{
out.write(buildings.get(i), "building_" + i, null);
}
out.write(lastFreeBuildingId, "lastFreeBuildingId", -1);
}
@Override
public void read(JmeImporter im) throws IOException
{
InputCapsule in = im.getCapsule(this);
mapSize = in.readInt("mapSize", -1); //This is line 1012 which it's crashing on
height = in.readInt("height", -1);
terrain = new TerrainBlock[mapSize][mapSize][height];
for(int i = 0; i < mapSize; i++)
{
for(int j = 0; j < mapSize; j++)
{
for(int k = 0; k < height; k++)
{
terrain[i][j][k] = (TerrainBlock) in.readSavable("terrain" + i + j + k, null);
}
}
}
buildings = new ArrayList<WorldObject>();
int buildingsAmount = in.readInt("buildingsAmount", -1);
for(int i = 0; i < buildingsAmount; i++)
{
buildings.add((WorldObject) in.readSavable("building_" + i, null));
}
this.lastFreeBuildingId = in.readInt("lastFreeBuildingId", -1);
}
And the mapSize variable is just a private int, so I simply don’t get why it crashes.
Any help would be appreciated.