Nifty - createPopup() problem [solved]

Hi all,

I am trying to implement popups into my project but somehow I get a nullpointer if I execute nifty.createPopup(…).

Here’s is a snippet of my code:

public void createPopup(){
    PopupBuilder popup = new PopupBuilder("Popup-Exit") {{
        childLayout(ElementBuilder.ChildLayoutType.Center);
        id("Popup-Exit");
        
        new PanelCreator() {{
           id("Test-Main0");
           height("30%");
           width("50%");
           childLayoutVertical();
           style("nifty-panel-simple");
        }}; 
    }};
    popup.registerPopup(nifty);
}

public void showExitPopup(){
   createPopup();
   Element element = nifty.createPopup("Popup-Exit");
   nifty.showPopup(screen, element.getId(), null);
}

Nifty is not empty, but still I cannot find the popup which created recently. What I am doing wrong?

Too bad we can’t see the NullPointerException or the line numbers because that will tell exactly on what line something is null.

That’s the NullPointerException:

Jan 29, 2015 2:15:07 PM com.jme3.app.Application handleError
Schwerwiegend: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at de.lessvoid.nifty.loaderv2.types.XmlBaseType.<init>(XmlBaseType.java:15)
at de.lessvoid.nifty.loaderv2.types.ElementType.<init>(ElementType.java:40)
at de.lessvoid.nifty.loaderv2.types.PopupType.<init>(PopupType.java:14)
at de.lessvoid.nifty.Nifty.createPopupFromType(Nifty.java:874)
at de.lessvoid.nifty.Nifty.createAndAddPopup(Nifty.java:927)
at de.lessvoid.nifty.Nifty.createPopup(Nifty.java:902)
at GUI.Popup.PopupControllerNeu.windowControl(PopupControllerNeu.java:58)
at Main.GameInput.onAction(GameInput.java:121)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onKeyEventQueued(InputManager.java:455)
at com.jme3.input.InputManager.processQueue(InputManager.java:831)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

The nullpointer will be shown if I execute this line “Element element = nifty.createPopup(“Popup-Exit”);”. I already checked this nullpointer and it seems like that somehow the popup has not been created correctly into the nifty object. And I have no clue why.

When you add nifty panels through java the correct code should be:

panel(new PanelBuilder() {{
           id("Test-Main0");
           height("30%");
           width("50%");
           childLayoutVertical();
           style("nifty-panel-simple");
        }}); 

It looks like when you used panel creator it was setting the ID to Test-Main0 and not Popup-Exit.

Thank you! :grinning: It’s working now.