[Fixed] closing popup doesn’t work, spams warnings

I’m trying to close a popup when the user pressed it’s OK button, but I can’t get it to work. Nothing happends when the user presses the OK button, except that the console gives a lot of warnings.

This is my popup code:

[java]package client._gui;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.controls.Controller;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.input.NiftyInputEvent;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.xml.xpp3.Attributes;

import java.util.Properties;





public class NiftyApp_Popup implements Controller

{

//<editor-fold defaultstate=“collapsed” desc=“screencontroller overrides”>

private Nifty nifty;

private Screen screen;

private Element popup;

public void bind( Nifty nifty, Screen screen, Element element, Properties parameter, Attributes controlDefinitionAttributes )

{

this.nifty = nifty;

this.screen = screen;

this.popup = popup;

}

public void onFocus( boolean gotFocus )

{

}

public boolean inputEvent( NiftyInputEvent inputEvent )

{

return true;

}

//</editor-fold>





public void onStartScreen()

{

}

public void init( Properties parameter, Attributes controlDefinitionAttributes )

{

}





public void ok()

{

nifty.getCurrentScreen().closePopup( popup, null );

}

}

[/java]



These are the warnings I get:

[java]aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker callMethod

WARNING: Exception: java.lang.reflect.InvocationTargetException

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: java.lang.reflect.Method invoke (Method.java:601)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1176)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1154)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:312)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty access$1500 (Nifty.java:73)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1371)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:161)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:235)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty update (Nifty.java:248)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:92)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.input.InputManager processQueue (InputManager.java:792)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.input.InputManager update (InputManager.java:856)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.app.Application update (Application.java:606)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.app.SimpleApplication update (SimpleApplication.java:230)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:184)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: java.lang.Thread run (Thread.java:722)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: Root Cause: java.lang.NullPointerException

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.screen.Screen closePopup (Screen.java:183)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: client._gui.NiftyApp_Popup ok (NiftyApp_Popup.java:61)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: java.lang.reflect.Method invoke (Method.java:601)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1176)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1154)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:312)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty access$1500 (Nifty.java:73)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1371)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:161)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:235)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: de.lessvoid.nifty.Nifty update (Nifty.java:248)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:92)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.input.InputManager processQueue (InputManager.java:792)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.input.InputManager update (InputManager.java:856)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.app.Application update (Application.java:606)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.app.SimpleApplication update (SimpleApplication.java:230)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:184)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)

aug 08, 2012 11:49:39 AM de.lessvoid.nifty.NiftyMethodInvoker logException

WARNING: java.lang.Thread run (Thread.java:722)[/java]



PS: these are the things I tried to close the popup: (they all gave the same warnings)

[java]

nifty.getCurrentScreen().closePopup( popup, null );

screen.closePopup( popup, null );

nifty.closePopup( popup,getId() );

[/java]

Theres an exception happening in your method.

Put a try/catch around the contents of your ok method and log the result.

Although I can tell just by looking at the code that popup is going to be null…since you set it to itself in the constructor then never do anything else with it…

1 Like

I did this:

[java] public void ok()

{

try

{

nifty.closePopup( popup.getId() );

}

catch( Exception e )

{

e.printStackTrace();

}

}[/java]



And got this:

[java]java.lang.NullPointerException

at client._gui.NiftyApp_Popup.ok(NiftyApp_Popup.java:63)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:601)

at de.lessvoid.nifty.NiftyMethodInvoker.callMethod(NiftyMethodInvoker.java:145)

at de.lessvoid.nifty.NiftyMethodInvoker.performInvoke(NiftyMethodInvoker.java:104)

at de.lessvoid.nifty.Nifty$DelayedMethodInvoke.perform(Nifty.java:1176)

at de.lessvoid.nifty.Nifty.invokeMethods(Nifty.java:1154)

at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:312)

at de.lessvoid.nifty.Nifty.access$1500(Nifty.java:73)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1371)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1329)

at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:161)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:235)

at de.lessvoid.nifty.Nifty.update(Nifty.java:248)

at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:92)

at com.jme3.input.InputManager.processQueue(InputManager.java:792)

at com.jme3.input.InputManager.update(InputManager.java:856)

at com.jme3.app.Application.update(Application.java:606)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:184)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)

at java.lang.Thread.run(Thread.java:722)[/java]



In other words, you were right.



[java]this.popup = popup;[/java]

was wrong, it should be

[java]this.popup = element;[/java]