Material not saved?

Hi!

I’m saving the rootNode of my App this way (like the tutorial):



[java]BinaryExporter exporter = BinaryExporter.getInstance();

JFileChooser jfc = new JFileChooser();

jfc.showSaveDialog(EditorMenu.this);

File f = jfc.getSelectedFile();

try {

exporter.save(app.getRootNode(), f);

} catch (IOException ex) {

Logger.getLogger(EditorMenu.class.getName()).log(Level.SEVERE, null, ex);

}[/java]



Works fine, I can open it in the Model Viewer of the SDK, BUT:



when I try to load it this way:

[java]

BinaryImporter importer = BinaryImporter.getInstance();

JFileChooser jfc = new JFileChooser();

jfc.showOpenDialog(EditorMenu.this);

Node node = null;

try {

node = (Node) importer.load(jfc.getSelectedFile());

} catch (IOException ex) {

Logger.getLogger(EditorMenu.class.getName()).log(Level.SEVERE, null, ex);

}

node.setName(“loaded Node”);

app.getRootNode().attachChild(node);

[/java]

I get the following exception:

[java]

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException

at com.jme3.material.Material.read(Material.java:1161)

at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:341)

at com.jme3.export.binary.BinaryInputCapsule.readSavable(BinaryInputCapsule.java:458)

at com.jme3.scene.Geometry.read(Geometry.java:553)

at com.jme3.export.binary.BinaryImporter.readObject(BinaryImporter.java:341)

at com.jme3.export.binary.BinaryInputCapsule.resolveIDs(BinaryInputCapsule.java:484)

at com.jme3.export.binary.BinaryInputCapsule.readSavableArray(BinaryInputCapsule.java:472)

at com.jme3.export.binary.BinaryInputCapsule.readSavableArrayList(BinaryInputCapsule.java:588)

at com.jme3.scene.Node.read(Node.java:599)

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)

[/java]

Do I also have to save all the Objects Materials?

You do realize you’re not supposed to use BinaryImporter directly right? If you configured your asset manager correctly, you would just be able to load the file using assetManager.loadModel().



As for the exception, it happens because you didn’t set the asset manager on the BinaryImporter, which is done for you when you use the asset manager to load the model.

1 Like