Hi guys i’m starting to learn some Nifty stuff but i can’t resolve a problem i’m having using more than one controller.
In the simpleInitApp method of the main class of my app i initialize nifty in this way:
[java]
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.registerScreenController(controller);
nifty.registerScreenController(controller2);
But… I got a NullPointerException. Debugging it i found it is caused by the Nifty variable being null in the controller2 because his bind method is never called.
I wanted to know why the bind is called on the first controller but not in the second one.
Also i read the tutorials and i found the stuff on the ScreenControllers implementing AppState, but i’m a bit confused if the problem is in some way related to not using the AppState to implement more than one ScreenController or not.
Thanks in advance.
So does your RootScreens.xml have many screens with different controllers for each of them? You sure its all setup up right? If so, then idk you could always pass nifty from your main class to your screen controllers. Or create a getter for it.
I wanted to add that I found that the bind method is called in the gotoScreen method, but this shouldn’t be the problem, infact i tried to only initialize the second controller and going in a screen dependent from him, and everything is ok, it seems that the problem is that the second controller is registered as “the second”.
I was thinking to do a test case tonight, i have no time this afternoon.
Already tried it, I had the problem when it was still there. However i will reinsert it until i have the problem.
Sorry but i have to leave, as i already said i’m busy this afternoon XD
Thanks for your support, i will probably post the test case tonight if things still won’t work.
While building the test case i finally found the solution.
In some point of the code i called a nifty.gotoScreen(“end”); but the name of the screen “end” has been changed in “ToggleIn”.
So nifty try to go to the screen end, can’t find the screen, and… I don’t know, something weird happens after that.
Anyway, thanks again for your support, Wez!