I'm new to Nifty GUI, so I'm following a tutorial here for making popups. For now, I'm just trying to get a very basic "test" popup to show, but I get multiple errors and none of them make much sense. To show a popup, I believe it is necessary to first have a Nifty Screen already showing, which I do. So here is the ScreenController for the working Nifty Screen:

public class WorkingScreen extends AbstractAppState implements ScreenController {

//Main is my jme SimpleApplication
private Main app;
private Nifty nifty;
private Screen screen;

public WorkingScreen() {}

public void equip(String slotstr) {
    int slot = Integer.valueOf(slotstr);
    System.out.println("Equipping item in slot "+slot);
    //Here's where it STOPS working.
    System.out.println("Registered new popup");
    Element ele = nifty.createPopup(app.getPlayer().POPUP);
    System.out.println("popup is " +ele);
    nifty.showPopup(nifty.getCurrentScreen(), ele.getId(), null);

public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.app = (Main)app;

public void update(float tpf) { 
    /** jME update loop! */

public void bind(Nifty nifty, Screen screen) {
    this.nifty = nifty;
    this.screen = screen;

When I call equip(0) the system prints Equipping item in slot 0, then a lot of errors and none of the subsequent println()'s. Clearly it botches somewhere in Player.registerPopupScreen(Nifty nifty). Here's the method:

public final String POPUP = "Test Popup";
public void registerPopupScreen(Nifty nifty) {
    System.out.println("Attempting new popup");
    PopupBuilder b = new PopupBuilder(POPUP) {{

            panel(new PanelBuilder() {{
                control(new ButtonBuilder("TestButton") {{
    System.out.println("PopupBuilder success.");
    System.out.println("Registerpopup success.");

Because that first println() doesn't show, it looks like this method isn't even called at all!


After removing all calls on the Player object, the popup works. It seems I'm not "allowed" to access the player from the ScreenController. Unfortunate, since I need information on the player for the popup. Is there a workaround?

  • \$\begingroup\$ +1 for a great question title. When taken outside of the jME / games context, it could mean just about anything. \$\endgroup\$
    – Engineer
    Nov 7 '11 at 21:47
  • \$\begingroup\$ lol.. I do plan on it being "nifty" as well :p \$\endgroup\$
    – Snailer
    Nov 7 '11 at 22:00
  • \$\begingroup\$ @Snailer Would you like me to migrate this to Stack Overflow? You might get an answer there. Either way, I strongly suggest you bring up this topic in the jME or Nifty GUI forums (or both); it appears to be a bit too specific for anyone here to answer. \$\endgroup\$
    – Ricket
    Nov 9 '11 at 17:46
  • \$\begingroup\$ I think it's best if this were closed, actually. At first I thought I was doing something wrong, but it appears to be more of a functionality with Nifty/JME. I'm slowly figuring out the limitations and working around it.. and if I need help the JME forums would probably be best. Thanks Ricket! \$\endgroup\$
    – Snailer
    Nov 9 '11 at 23:58

A old question but anyway, I suspect that I know what the problem is.

Depending on how your implement the reference to the ScreenController Nifty will create a new instance of the referred class. I guess this is the problem that is pestering you. It results in two instances of this class, one that is maintained by JME and that contains the proper references to the player and so on, and one newly created that contains no references but is used and referred to by Nifty.

To solve this you have to use the registerScreenController() funktion auf the Nifty class to register the correct instance of the screen controller before the actual GUI is load from the XML file or build using Java.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.