Problems using a class

I created the following class to create walls.



[java]public class Wall extends SimpleApplication{

// AssetManager assetManager;

BulletAppState bulletAppState;

//Method to create a wall

protected Geometry makeWall(String name, float x, float y, float z,

float px, float py, float pz) {

Box box = new Box(Vector3f.ZERO, x,y,z);

Geometry wall = new Geometry(“wall”, box);

wall.setLocalTranslation(px,py,pz);

Material mat1 = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

mat1.setColor(“Color”, ColorRGBA.Magenta);

wall.setMaterial(mat1);

RigidBodyControl box_phy = new RigidBodyControl(0.0f);

wall.addControl(box_phy);

box_phy.setFriction(0.0f);

box_phy.setRestitution(1f);

bulletAppState.getPhysicsSpace().setGravity(Vector3f.ZERO);

bulletAppState.getPhysicsSpace().add(box_phy);

return wall;

}

[/java]



Then, I called this method in my game:

[java]public class Game extends SimpleApplication{

public static void main(String[] args ) {

Game app = new Game();

app.start();

}

Node walls;

RigidBodyControl wall_phy;

BulletAppState bulletAppState;

Wall w = new Wall();



public void simpleInitApp(){;

bulletAppState = new BulletAppState();

walls = new Node (“geometrie”);

rootNode.attachChild(walls);



walls.attachChild(w.makeWall(“wall”, 1.10f,1.10f,0.10f,

4f, -.10f, 2.20f));

}

[/java]



The problem is that when I run the program I get the following error:

java.lang.NullPointerException

at mygame.Wall.makeWall(Wall.java:39)

at mygame.ShootingGame.simpleInitApp(ShootingGame.java:84)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:228)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.ja



It seems that the error is caused by this line from the class Wall:

Material mat1 = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);



Can anybody give me an advice of what I am doing wrong

You never actually create the BulletAppState in your wall class, nor pass it the BulletAppState you create in your main class.

The error says what line it occurred on: line 39 in Wall.java

1 Like

This is the line where it occurred:

java.lang.NullPointerException

at com.jme3.material.Material.(Material.java:116)

Then why did you post this?:

java.lang.NullPointerException
at mygame.Wall.makeWall(Wall.java:39)
at mygame.ShootingGame.simpleInitApp(ShootingGame.java:84)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:228)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.ja
1 Like

I just forgot to include:

java.lang.NullPointerException

at com.jme3.material.Material.(Material.java:116)

at mygame.Wall.makeWall(Wall.java:39)



And I thought that the other information was relevant to figure out what was wrong with my code…

Are you sure you want to inherit simple application in your wall? Why would you have more than one simple application in your application?

Wait, Wall is a SimpleApplication and so is Game. You just need one class that extends SimpleApplication.

Fix that and it will fix your problem (the asset manager is null when you pass it to the material)

1 Like

“Yo, dawg, we heard you like applications… so we put applications on yo’ applications…”