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 IngameState.java

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
      timer.update();
      interpolation = timer.getTimePerFrame();
     
GameStateManager.getInstance().update(interpolation);
      //Check if Escapekey has been pressed
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
         finished = true;
      }
   }
 

   protected void render(float interpolation)
   {
       GameStateManager.getInstance().render(interpolation);
   }




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

   @Override
   public void render(float interpolation)
   {
          DisplaySystem.getDisplaySystem().getRenderer().clearBuffers();
          DisplaySystem.getDisplaySystem().getRenderer().draw(this.RootNode);
   }

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


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



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

Regards,
Boethio

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:



import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;

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 ");
      manager.getSettings().setSFX(false);
      manager.getSettings().setMusic(false);
      manager.getSettings().setWidth(800);
      manager.getSettings().setHeight(600);
      manager.getSettings().setFullscreen(false);
      manager.getSettings().setStencilBits(4);
      manager.start();
      
      // initiate the different states
      ingamestate = new ingame("Main Menu");      
      // Activate the game state   
      ingamestate.setActive(true);
      // Add it to the manager   
      GameStateManager.getInstance().attachChild(ingamestate);
   }

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

}



which gives me easy access to rootNode and Camera

I just have to call

statemanager.manager.getCamera();
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.





Regards,

Boethio

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: