Getting extension of extension of Simple Application

Hello,

I am writing a little Environment.
I used a class extending Simple Application for the main Environment named Spielbrett.

public class Spielbrett extends SimpleApplication {

    public static void main(String[] args) {
        Spielbrett app = new Spielbrett();
        app.start();
    }

@Override
    public void simpleInitApp() {
            Spielstein stone = new Spielstein(0,0);
    }
        

Now I wanted to add Spatial objects with some variables,
so I created another class for these objects, called Spielstein and extending Spielbrett:

public class Spielstein extends Spielbrett{
    public Spatial stone;
    public int player;
    public int team;

public Spielstein(int t_player, int t_team){
        Spatial t_stone = assetManager.loadModel("Models/stone/stone.j3o"); //In this line shall be the error
        //set color:
        if (t_team == 0) { //team 0 set color to blue
            Material mat_blue = ((Material)assetManager.loadMaterial("Materials/blue.j3md"));
            t_stone.setMaterial(mat_blue);
        }
        //assign this variables
        this.stone = t_stone;
        this.player = t_player;
        this.team = t_team;

        rootNode.attachChild(stone);
    }
   

As you see I do some actions in the constructor, that needs the AssetManager from simpleApplication.
That was the reason I extended Spielstein with Spielbrett.
Now I get an
Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException

in the line, where Spatial t_stone is defined (the line with comment above set color).

Can anyone give me a clue? I am very new to Java and don’t really understand the extending function…

How many applications do you want in your application? Just like you shouldn’t create a whole new car inside of your car just to reach the radio knobs… you shouldn’t create a whole new application inside of your application just to avoid passing some parameters.

In this case, the second application was never started so it’s not going to have any of the stuff initialized… nor do you want to start it because that’s not really what you want to do. It’s possible that some Java tutorials might be helpful for you.

Well yes, true, it was a bad idea to extend the class.
Is there another way to use assetManager? Or import something to be able to use this Object?

Okey I finally found the use of this class here:
https://code.google.com/p/jmonkeyengine/source/browse/BookSamples/src/chapter04/guiappstate/StartScreenState.java?r=10595

Well yes, true, it was a bad idea to extend the class.
Is there another way to use assetManager? Or import something to be able to use this Object?

Okey I finally found the use of this class here:

Pass it as a parameter to your new class or whatever. I strongly suggest also learning a little more about Java. It will save you tons of time down the road.

Well, yes, I am on my way to learn java. But sadley I don’t have much time for tutorials…

Okey, I want to pass it as a parameter. I first tried a import, but of course it was a different AssetManager, which was not very good style.

So, I also thought about a pass.
But I can’t access the assetManager from the other class.

I made a simple function

public AssetManager getAM(){
        return assetManager;
    }

but it is not visible on other classes.
Is the reason, that it’s extended by Simple Application?
Or because it is static and the other class isn’t?

[java]
public class MyOtherClass {
private AssetManager assetManager;

public MyOtherClass( AssetManager assetManager ) {
    this.assetManager = assetManager;
}

public void someMethod() {
   // do stuff with asset manager.
}

}
[/java]

If coding were mountain climbing, this sort of thing is the equivalent to tying your shoes.

Question: if you don’t have time to learn the language then why are you bothering at all?

1 Like

Okey, you were allright just from the beginning.
I didn’t understand the pass-Parameter at first.
But it’s simple now:
When I am calling a new Spielstein Object, I pass with the parameters team and player the assetManager.

Thanks for your support. And excuse my blind.