Hello, I’m new to the forum and obviously new to the jMonkeyEngine3. If that matters, I’m using the nightly builds.
The problem is as in the title: the same line that works in Main doesn’t in a different class. I have an AssetManager field but the line
[java]Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);[/java]
throws a NullPointerException. What should I do?
Thanks in advance.
could you post the complete stack trace please?
This line can hardly throw that kind of exception.
Yup, sorry for not posting it in my previous post, I thought it was some kind of common noob mistake:
2011-02-20 11:22:50 com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.material.Material.(Material.java:166)
at mygame.Cor.makeWall(Cor.java:52)
at mygame.Cor.r(Cor.java:40)
at mygame.Main.simpleInitApp(Main.java:36)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:218)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:136)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:193)
at java.lang.Thread.run(Thread.java:619)
ok you assetManager is null.
where do you call it? do you use SimpleApplication?
No, my assetManager is in the class Cor that doesn’t extend anything. I guess I should use assetManager.registerLocator(); but I’m not sure what are those parameters it takes.
no you should pass the assetManager to the Cor class from the simpleApplication.
what do you do then?
AssetManager assetManager;
Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
???
I used this method getAssetManager(); and made a new method that returned assetManager but both gave me the same stack trace.
If you just put a field there its null. You have to assign a value to it… So in the constructor of the class you go something like:
[java]
public MyClass(AssetManager manager){
this.assetManager=manager;
}
[/java]
Thanks guys, it’s working now!