Null Pointer Exception in Material

Hi,



I’m getting this problem:



AM 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:133)

at mygame.TileManager.Load(TileManager.java:36)





The program works fine when run from with in the IDE (where I can debug it) but fails when I run the jar file (java -jar MyGame.jar ).



I guess it runs into trouble trying to load the terrain file in the lib directory under dist. I have the mattarials in the lib/assets.jar file (MatDefs/Terrain/Terrain.j3m).



So, any1 have any idea what the prob is and how to fix it?



Thanks.

I guess you want help right? Then post the code where you manage that material. Without that there isn’t much we can do except ask question and drag this for a long time until we get what we need to diagnose the problem in your code. :slight_smile:

Though “works from the IDE but doesn’t work from command line” is the classic symptom for not doing assets properly. I agree with madjack, at this point we can only guess which asset is a problem.

Yep. My guess is, the material is used like “assets/Textures/this.png” or something like that…

Here’s the code :



/** 1. Create terrain material and load four textures into it. */

m_MatTerrain = new Material(assetManager,

“Common/MatDefs/Terrain/Terrain.j3md”);



I’m more or less just copying from the from the tutorials but I have shifted the material handling to a separate class and passed the assetManager in the constructor.



Thanks.

Are you running java -jar from the dist directory or somewhere else?

Also, when did you last update? You seem to be running a very old version of the SDK as I had to go back to the March source code before I could find a version of Material.java that could even possibly throw an NPE on line 133. And I’m not even sure that’s the right code… it’s just that later versions could not possibly have thrown an NPE there.

Last I checked material loading was used this way: (at least that’s how I do this and I don’t have problems)



[java]

material = app.getAssetManager().loadMaterial(“Materials/Stars/Star.j3m”).clone();

[/java]

@madjack said:
Last I checked material loading was used this way: (at least that's how I do this and I don't have problems)

[java]
material = app.getAssetManager().loadMaterial("Materials/Stars/Star.j3m").clone();
[/java]


The other way works fine, too. It's the one that I use.

If it works in the IDE and not from the command line then something about the command line environment is wrong. Most likely that the other jars aren't where they are supposed to be or something.

I can't tell for sure until I know which old version of JME the OP is running.
@pspeed said:
Are you running java -jar from the dist directory or somewhere else?

dist directory

@pspeed said:
Also, when did you last update?


I have version 3.5 beta. I did a check with the update plugin and it said I'm up to date.


@madjack said:
Last I checked material loading was used this way: (at least that's how I do this and I don't have problems)

[java]
material = app.getAssetManager().loadMaterial("Materials/Stars/Star.j3m").clone();
[/java]


Ok, I'll try that. Thx
@madjack said:
Last I checked material loading was used this way: (at least that's how I do this and I don't have problems)

[java]
material = app.getAssetManager().loadMaterial("Materials/Stars/Star.j3m").clone();
[/java]


Well, that gave me he error :


SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ClassCastException: com.jme3.material.MaterialDef cannot be cast to com.jme3.asset.CloneableSmartAsset

hmm … as I got the Class cast exception, I changed the code back to how it was, rebuilt and it now works!