Problem using communication between appstates

Hello,
I’m trying to communicate between appstates using the tutorials. I have used them before but this time for some reason, I keep getting null pointer exceptions. Here is one line;

@Override
public void initialize(AppStateManager stateManager, Application app)
{
super.initialize(stateManager, app);
this.app = (SimpleApplication)app;
this.inputManager = this.app.getInputManager();
this.stateManager = this.app.getStateManager();

  SkyrunnerGeometry = this.stateManager
                    .getState(Skyrunner3DModelState.class)
                    .SkyrunnerGeometry;//<---wants a spacial here


  KeyboardAndMouseState startKeyboardAndMouse = new KeyboardAndMouseState
    (
          SkyrunnerGeometry,
          inputManager, 
          camera
    );
  stateManager.attach(startKeyboardAndMouse);

I originally had everything inline but seperated to try to find the issue. It seems that I don’t have a problem until I have to return a value.

Here is the error I get:
Dec 29, 2014 9:54:36 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at MainCore.InitializeGame.initialize(InitializeGame.java:52)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

Sorry I want to be notified when someone replies.

Which line is line 52?

I believe you are asking for a value of appState B, from appState A.
For that to work, you need to attach appState B before appState A.
Or set that value through appState B’s constructor instead of appState B’s initialize method.

Hey all,
Thanks for the fast reply. I’m sorry I didn’t get back with any of you quickly but this system didn’t inform me that anyone responded or maybe its in my junk mail. I am trying a different route now looking at the JMonkeyEngine cookbook this time. Unfortunately, I’m getting the same results. I tried to connect my gravity appState first before messing with the bullet again but that didn’t work either. Here is my new code;

public class InitializeGame extends AbstractAppState
{
public SimpleApplication app;
public BulletAppState bulletAppState;
public InputManager inputManager;
public AppStateManager stateManager;

//public AppState ThirdPersonPlayerState;
Geometry SkyrunnerGeometry;

//BetterCharacterControl variables
private Camera cam = new Camera();
private float physicsDamping = 3f;
        
/**
*
* @author brian
* Initialize all the game stuff here
* 
*/
@Override
public void initialize(AppStateManager stateManager, Application app) 
{
  super.initialize(stateManager, app); 
  this.app = (SimpleApplication)app;
  this.inputManager = this.app.getInputManager();
  this.stateManager = this.app.getStateManager();
  
  /*
   * Call the initializeGamePhysics class contructor to initialize a new 
   * physics object.  Attach it to the stateManager after that so that its 
   * an appState.  This appState should get turned off when the active game
   * state is exited.
  */
  InitializeGamePhysics mainGameGravityOn = new InitializeGamePhysics();
  stateManager.attach(mainGameGravityOn);
  
  
  /***********************************************************************
   *     ACTION!!!
   *    Initialize the mouse and keyboard so the player can interact
   ***********************************************************************/
  Node playerNode = new Node("Player");
  ThirdPersonPlayerControl charControl 
          = new ThirdPersonPlayerControl(0.5f, 2.5f, 8f);
  
  //Get control of the game engine's camera
  charControl.setCamera(cam);
  
  //Add a control to the player node
  playerNode.addControl(charControl);
  
  //Skyrunner is flying and has no weight so make gravity zero
  charControl.setGravity(Vector3f.ZERO);
  
  //Simulate prayer boosting with damping.
  charControl.setPhysicsDamping(physicsDamping);

  this.stateManager.getState(BulletAppState.class)
                   .getPhysicsSpace()
                   .add(charControl);

My errors are:

Dec 30, 2014 4:31:38 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at MainCore.InitializeGame.initialize(InitializeGame.java:89)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

The specific line its pointing to is 91 which is:

this.stateManager.getState(BulletAppState.class)
.getPhysicsSpace()
.add(charControl);

Ok, I figured out what was wrong. I was instantiating a new BulletAppState object but not attaching it to the stateManager. Silly me.