Saving and loading nodes in custom classes -> nullpointerexception

Hi all!
I know that i can export/import nodes to/from j3o files with the BinaryExporter/Importer and just dump them all in one node if i only want one file
but! i allso have custom classes that have to be saved and i want to save the custom class info in the same File as my Node
so my best try at it looks something like this:
(using savable interface)
out:
capsule.write(theNode, “theNode”, new Node() );
in:
Geometry theNode = (Node) capsule.readSavable(“theNode”, new Node() );

after this didnt work i tried to just save the Geometry of the Node:
out:
capsule.write(((Geometry) theNode.getChild(0)), “theGeom”, new Geometry() );
in:
Geometry geom = (Geometry) capsule.readSavable(“theGeom”, new Geometry() );
theNode = new Node();
theNode.attachChild(geom);
dosnt work either and i tried to find the error line ->

when reading the geometry (savable read method in class Geometry) the line that fails to execute seems to be so that it can’t even compile (which dosnt make sense obviously because it got compiled for the programm) so im totally confused.

can anybody help me how can i save a node from in a custom class?

Are you using the SDK or some other IDE?

InputCapsule definitely has a method that takes two parameters: http://hub.jmonkeyengine.org/javadoc/com/jme3/export/InputCapsule.html#readString(java.lang.String,%20java.lang.String)

if i understand it complains because it has a String Instance and a Object Instance.
(using SDK)
i just noticed something in the wiki:
when you save a model that has textures […] the textures have to be accessible at the exact location (relative to the assetmanager root).
if i load a model that is not in the assetmanager root the exporter might not be able to save the path relative to the assetmanager…
i’ll just try that out
any help is awesome!
verry grateful

<cite>@emtonsit said:</cite> if i understand it complains because it has a String Instance and a Object Instance.

The message is completely 100% wrong, though. “null” is any type and should match the string version of the method. Something very strange is going on.

Problem seems to be solved:
The error was occuring in the material.java in line (1119) :

def = (MaterialDef) im.getAssetManager().loadAsset(new AssetKey(defName));

didnt know i had to set the assetmanager of the BinaryImporter manualy…
-> Nullpointer exception because it hasnt got the assetManager

BinaryImporter importer = BinaryImporter.getInstance();
-> importer.setAssetManager(assetManager);
Savable test = importer.load(file);

for anyone who has the same Problem

1 Like