Problem with writeSavableArrayList()

Hi guys. I’m having a strange issue when trying to save an ArrayList of integers.



Whenever capsule.writeSavableArrayList() is executed inside write(), the program crashes.

Here’s the related log:



SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.ClassCastException: java.lang.Integer cannot be cast to com.jme3.export.Savable

at com.jme3.export.binary.BinaryOutputCapsule.writeSavableArrayList(BinaryOutputCapsule.java:758)

at com.jme3.export.binary.BinaryOutputCapsule.writeSavableArrayList(BinaryOutputCapsule.java:346)

at game.HeroStatus.write(HeroStatus.java:251)

at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:376)

at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:721)

at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:734)

at com.jme3.export.binary.BinaryOutputCapsule.writeStringSavableMap(BinaryOutputCapsule.java:814)

at com.jme3.export.binary.BinaryOutputCapsule.writeStringSavableMap(BinaryOutputCapsule.java:380)

at com.jme3.scene.Spatial.write(Spatial.java:1270)

at com.jme3.scene.Node.write(Node.java:589)

at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:376)

at com.jme3.export.binary.BinaryExporter.save(BinaryExporter.java:185)

at jme3tools.savegame.SaveGame.saveGame(SaveGame.java:54)





The problem does not occur if I save an empty ArrayList.



So, can you please help me with this? Thanks in advance.

SavableArrayList saves an ArrayList of Savables (classes that implement the Savable interface). You have an Integer in your ArrayList.

Thanks for the quick reply, normen. I thought this method could save any ArrayList.



So is there a way to save an ArrayList of integers?

Create a wrapper for Integer implementing savable or create a wrapper for the array list that saves the contents?

Thanks, zarch! Creating a wrapper class for int implementing Savable worked just fine!



I hadn’t used a wrapper class before, so I didn’t know about it.



Thanks again!