Nifty throws NullPointerException every now and then [SOLVED]

Hehe… thanks for those encouraging words… LOL :smiley:



For now, the menu pops up where I want it to pop up and it does not pop up outside the screen, so maybe I will stick to this for now without merging to nifty popup.

@husky said:
Thanks mates! It turns out that the exit() is indeed the problem here :roll:


I had a strong feeling the exit() method was fishy but not being able to exactly see what was inside stopped me from replying.


Using the following code solved this issue:
To display the menu -->
[java] nifty.getScreen("actionsmenu").findElementByName("panel_menu_background").setVisible(true);
nifty.gotoScreen("actionsmenu");[/java]
and to hide it -->[java]myGame.nifty.getScreen("actionsmenu").findElementByName("panel_menu_background").setVisible(false);[/java]

My apologies for being stubborn!

I don't know where that code is, but here all the panels and stuff I want to turn off at the start of the screen is in bind(...).
1 Like

@madjack:

This code is in my actionsListener and in my menucontroller. I have been wondering what the bind() exactly does and have not yet dig into it. From what I understand, in the bind() there is a reference from the controller to the screen? Well, as I said: I will take a closer look at it, as well as to some examples, I guess.



It is about time I am going to optimize the code anyway, because it is getting messy and the architecture is not suitable for the game at all: There is not much flexibility yet :).

Bind(…) is to ScreenControllers what initialize(…) is to AppStates.

If you let nifty create the controller instead of creating one yourself and passing it in then bind is how the controller gets its nifty instance etc. It’s also useful for storing a reference to the screen.



So for example most of my controllers have a member variable for Nifty and Screen and set them in the bind() method.



Just remember that your controller can exist for a while before being bound (it’s only bound the first time the screen is viewed iirc) so be aware the variables could be null.

@zarch said:
Just remember that your controller can exist for a while before being bound (it's only bound the first time the screen is viewed iirc) so be aware the variables could be null.


Can't say I've ever experienced this, but I will keep this in mind if I ever get some weird null result.

The cases I had it happen were when a player connected to the server where they were already in a game and had been disconnected. They were immediately reconnected to the ongoing game but the actual in-game nifty screen hadn’t been bound yet so null pointer exceptions were thrown.



The controller existed as it was created in simpleInitApp but the screen hadn’t been created yet.



I didn’t investigate in any great detail but it definitely can happen.

No network in Disenthral. SP game only. :slight_smile:



Still, good to know.