I have three screens and two controllers that I have set up and can transition through them in one direction but having a problem going back to a previous screen.
When I start the app I set up my states MenuState and RunState and attach them to the statemanager.
In the menustate I do this:
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(),
nifty = niftyDisplay.getNifty();
nifty.fromXml(“Interfaces/screen.xml”, “start”, this);
As you can see I have tried using addScreen to the nifty instance but this doesn’t change my issue.
I can move from the start screen (which allows the user to log on) to the menu screen which allows some choices before moving to the run state. Once in the runstate I get a null pointer exception when trying to go back to the menu state.
[java]private void leaveScreen()
System.out.println(“Leaving Run Screen”);
MenuState menuState = state.getState(MenuState.class);
//TODO save state here
the goToScreen method throws an NullPointerException.
In the bind method I do this
[java]this.nifty = nifty;
this.screen = screen;
System.out.println(nifty + " " + screen + " in RunState");[/java]
and the println gives me[java] de.lessvoid.nifty.Nifty@43dcc7b5 de.lessvoid.nifty.screen.Screen@3f5f15b in RunState[/java]
but the println from leaveScreen prints a null for the nifty variable.
How can I fix this? It appears that when I call leaveScreen I am calling on a different object that has not had bind called but the only place I create a runstate is in main and attach it to the statemanger. When I move forwards from the menustate I get that instance from the statemanager.