Null Pointer exception when loading Unshaded.j3md

I’m getting this error when I try to load a material from my obstacle class:


at com.jme3.material.Material.<init>(

at pawn.Obstacle.Create(

at pawn.Main.createObstacles(

at pawn.Main.simpleInitApp(


at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(



obstacle create looks like this:

[java]public Geometry Create (){

Box body = new Box(new Vector3f(1,2,1), 0.5f, 0.5f, 0.5f);

Geometry geom = new Geometry (“Body”, body);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

Texture tex = assetManager.loadTexture(“Textures/sq_face_green.jpg”);

mat.setTexture(“Color Map”, tex);


return geom;

} [/java]

how would I fix this? thanks in advance!

Probably the texture is null, check the file case and name.

I just checked the filename and file path, everything seems to be in order there, the name is copied directly from the file itself.

can you check if “tex” is null after you load it? I am almost 100% positive that must be it.

hmm, the funny thing is the tex line is never even run, the game crashes on the [java] Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");[/java]

Are you working with OSGi? Or with threads?

nope nothing complicated like that, infact I was able to load these textures before when I was loading (via a method) them in the main class, but that proved to be ineffective since I wanted obstacles to have variations and different properties so that called for classes. I don’t know if it helps but here is the entire obstacle class:


  • To change this template, choose Tools | Templates and open the template in
  • the editor.


    package pawn;

    import com.jme3.material.Material;

    import com.jme3.math.Vector3f;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.shape.Box;

    import com.jme3.texture.Texture;

    import com.jme3.asset.AssetManager;


  • @author Alex


    public class Obstacle {

    protected int Id = 0;

    protected String Name = "Normal Block";

    protected int health = 100;

    protected int attack = 0;

    private AssetManager assetManager;

    public Geometry Create (){

    Box body = new Box(new Vector3f(1,2,1), 0.5f, 0.5f, 0.5f);

    Geometry geom = new Geometry ("Body", body);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    Texture tex = assetManager.loadTexture("Textures/sq_face_green.jpg");

    mat.setTexture("Color Map", tex);


    return geom;


    public void Take_Damage (int hit){


    public int getAttack (){

    return attack;




    and here is the create obstacles method:

    [java]public void createObstacles(int width, int length){

    Random r = new Random();

    for(int q = 0; q < length; q++)

    for(int i = 0; i < width; i ++){

    if (r.nextInt(3)== 0){

    int id = r.nextInt(1);

    if ( id == 0){

    Obstacle ob = new Obstacle();



    if (id == 1){

    HeavyBlock ob = new HeavyBlock();






    This isnt the best design I know but right now im just playing around with a few things.

My guess: assetManager is null. I don’t see anywhere above that it gets set.

1 Like

Sorry for the extreme nooby question Im about to ask but what should I set asset manager to?

The asset manager that you have in your application class. Variables that aren’t set to anything don’t have any values.

Writing 3D games is one of the hardest types of programming to do… and that’s for people who already know the language. You should consider investing some more time in learning Java without the added burden of trying to learn 3D games. If you have the patience to do that then the rest of your coding life will go 1000 times easier.

Well, Im actually taking a java course right now :slight_smile: We are almost done and really Im doing this just to play around and see where I can go with it not too worried about a full fledged game. Thanks for the help though!


:D. You’ve understood the spirit of the thing. The last one we gave him that link, was very embarrassed