Hello,
I am working on a mapeditor and decided to begin with saving and loading mapdata before I build stuff
I am working with the savable Interface.
Loading, saving and then comparing two Tiles works flawlessly.
[java]public class Tile implements Savable{
boolean pathable;
int height;
//shortened Version without constructors or equals method
public void write(JmeExporter ex) throws IOException {
OutputCapsule capsule = ex.getCapsule(this);
capsule.write(height, "height", 0);
capsule.write(pathable, "pathable", false);
}
public void read(JmeImporter im) throws IOException {
InputCapsule capsule = im.getCapsule(this);
capsule.readInt("height", 0);
capsule.readBoolean("pathable", false);
} }
[/java]
I use Import and Exportcapsules of the JmeImporter and exporter.
Ints and Booleans load fine.
Now to the same situation with two maps.
[java]public class Map implements Savable {
private int xSize;
private int ySize;
private Tile[][] tiles;
// shortened Version again
public void read(JmeImporter im) throws IOException {
InputCapsule capsule = im.getCapsule(this);
xSize = capsule.readInt("xSize", 0);
ySize = capsule.readInt("ySize", 0);
Savable[][] temp = capsule.readSavableArray2D("tiles", null);
tiles = (Tile[][]) temp; //
"EXCEPTION HERE"
}
public void write(JmeExporter ex) throws IOException {
OutputCapsule capsule = ex.getCapsule(this);
capsule.write(xSize, "xSize", 0);
capsule.write(ySize, "ySize", 0);
capsule.write(tiles, "tiles", null);
}
[/java]
As noted, tiles = (Tile[][]) Temp; gives me my Exception: (SCHWERWIEGEND = Critical)
[java]SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ClassCastException: [[Lcom.jme3.export.Savable; cannot be cast to [[Lmapeditor.Tile;
at mapeditor.Map.read(Map.java:111)
at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:341)
at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:243)
at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:130)
at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:271)
at com.jme3.export.binary.BinaryImporter.load(BinaryImporter.java:266)
at mapeditor.Main.simpleInitApp(Main.java:38)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:228)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:679)[/java]
My Tile is Savable, so why can I not cast it from Savable to Tile?