Problem Loading AppState

I have defined two classes that extend AbstractAppState and I am having trouble switching between them. In my screen.xml file I have three screens declared:

[java]<screen id=“start” controller=“states.MenuState”>
<screen id=“menu” controller=“states.MenuState”>
<screen id=“runState” controller=“states.MazeRunState”>[/java]

As you can see the two classes are MenuState & MazeRunState both in the states package. From within the update method of MenuState I have this:

MazeRunState runState = new MazeRunState(user, mazes.get(mazeIndex));

Which appears to work but I have noticed that I have a warning:

[java]WARNING: class [states.MazeRunState] could not be instantiated (java.lang.InstantiationException: states.MazeRunState)
Feb 09, 2014 2:36:30 PM de.lessvoid.nifty.screen.Screen <init>
WARNING: Missing ScreenController for screen [runState] using DefaultScreenController() instead but this might not be what you want.[/java] In the output console.

I have placed the code:

[java]System.out.println("Running " + tpf);[/java] In the MazeRunStates update method and it prints as I would expect. Whats wrong here?

Where’s the code where you call nifty.fromXML/addXML? These screencontrollers haven’t been properly registered with nifty, and so nifty creates it’s own instance using the default constructor

The code is in the MenuState.initialize method:

[java]NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(),
nifty = niftyDisplay.getNifty();
nifty.fromXml(“Interfaces/screen.xml”, “start”, this);

Copying this code to the MazeRunState caused other errors but are you saying that is what I need to do. That code above gives me the start screen, then later

[java]nifty.gotoScreen(“menu”);[/java] gets me to the menu screen.

The update method has the third call to

[java]nifty.gotoScreen(“runState”);[/java] and the MazeRunState is created as its update method is outputting to the console and the screen goes blank as I would expect because I only have a layer defined in this screen. However I still get the warning. Is it related to the “this” I have used in the fromXml call which relates to the MenuState object?

you need to do [java]nifty.fromXml(“Interfaces/screen.xml”, “start”, this, InsertMazeRunStateInstanceHere);[/java]

Nifty needs a reference to your MazeRunState object, so that it can operate as you think it should

Thanks it looks like I have two choices I can do it as you have shown or I could call registerScreenController when I have my controller instance available.