So I have this code:
[java]import java.io.File;
import java.io.IOException;
import com.jme3.app.SimpleApplication;
import com.jme3.export.binary.BinaryExporter;
import com.jme3.export.binary.BinaryImporter;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
public class JMETESTER extends SimpleApplication {
/**
-
@param args
*/
public static void main(String[] args) {
JMETESTER app=new JMETESTER();
app.start();
}
@Override
public void simpleInitApp() {
Node gameNode=new Node();
Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin
Geometry geom = new Geometry(“Box”, b); // create cube geometry from the shape
Material mat = new Material(assetManager,
“Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material
mat.setColor(“Color”, ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube’s material
gameNode.attachChild(geom); // make the cube appear in the scene
try {
BinaryExporter.getInstance().save(gameNode, new File(“asdf.txt”));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Node n=null;
try {
n = (Node) BinaryImporter.getInstance().load(new File(“asdf.txt”));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
rootNode.attachChild(n);
}
}
[/java]
SO it basically saves a node then reloads it, but I keep getting a NullPointerException in material when I do
[java]n = (Node) BinaryImporter.getInstance().load(new File(“asdf.txt”));[/java]
[java]java.lang.NullPointerException
at com.jme3.material.Material.read(Material.java:1119)
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:559)
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:598)
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 JMETESTER.simpleInitApp(JMETESTER.java:46)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)[/java]
So my guess is it’s messing up the assetManager’s root directory. How do I fix this?