GameState problem - RootNode NullPointer Reference

A null-pointer exception is always a runtime-error and never a compiler-error.

Anyway, your exception is in line 191 of

Should be easy to fix.

When not: post this line here and not the entire source-code, please.

ok, thats exactly what i thougt. but it turned out not being so easy.

line 191:

         this.RootNode.updateGeometricState(interpolation, true);      //Update Geometry

But I initilialize the RootNode in the Constructor of my IngameState-Class:

        this.RootNode = new Node("Ingame-Root-Node");

And i dont get why it is NULL when I call the update function of IngameState via the update function of myinvaders-class (my application main class).
These are the main render/update functions:

   protected void update(float interpolation) {
      //update the time to get the framerate
      interpolation = timer.getTimePerFrame();
      //Check if Escapekey has been pressed
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
         finished = true;

   protected void render(float interpolation)

These are the IngameState render/update functions (here is the RuntimeError):

   public void render(float interpolation)

   public void update(float interpolation)
// A lot of Code in between

         this.RootNode.updateGeometricState(interpolation, true);      //Update Geometry
         this.RootNode.updateRenderState();                     //Update Renderer

I guess I implemented render/update wrong in my IngameState-Class.


Are you sure your constructor is executed?

You could add some outputs to your code to track down when you RootNode is set to null.

hmm, usually when I work with a gamestate, I build the manager like this:


public class statemanager{

   public static StandardGame manager;

   public static ingame ingamestate;

   public statemanager(){
      // initiate the main game, which is running off standard game
      manager = new StandardGame("JMonkey Game ");
      // initiate the different states
      ingamestate = new ingame("Main Menu");      
      // Activate the game state   
      // Add it to the manager   

   public static void main(String[] args) throws Exception {
      new statemanager();


which gives me easy access to rootNode and Camera

I just have to call

or, incase of my gamestate (which extends BasicGameStateNode) i just call, Node rootNode = super.rootNode;

but in your case...

And i dont get why it is NULL when I call the update function of IngameState via the update function of myinvaders-class (my application main class).

perhaps the reason for that is that your rootNode was never initiated because all you did was run the update, and never called rootNode = new Node();

Of course I could be wrong because I am pretty new at this. But good luck! :)

Ok, I got it fixed.

The constructor was implemented "public void IngameState()"

And this of course is not a constructor, so i removed void and got it working.

oh man,  i am so eased now :slight_smile:

PS: Thanks for the really quick replies, i didnt expect that.



You could add "super();" to your constructors in the future, to prevent such a problem. Eclipse will complain, when you call "super();" from anywhere else, than the first line of a constructor.

I'm happy that you fixed it. :slight_smile: