logException onClick

Hi, im getting this exception when i click in any button with a attached method

[java]
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker callMethod
Advertencia: Exception: java.lang.reflect.InvocationTargetException
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: java.lang.reflect.Method invoke (Method.java:606)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1174)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1152)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:354)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty access$1700 (Nifty.java:77)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1374)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme handleMouseEvent (InputSystemJme.java:124)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:232)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:296)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty update (Nifty.java:288)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:113)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.input.InputManager processQueue (InputManager.java:819)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.input.InputManager update (InputManager.java:883)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.app.Application update (Application.java:604)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.app.SimpleApplication update (SimpleApplication.java:231)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:185)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: java.lang.Thread run (Thread.java:744)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: Root Cause: java.lang.NullPointerException
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: mygame.MainMenuState quit (MainMenuState.java:67)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: java.lang.reflect.Method invoke (Method.java:606)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1174)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1152)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:354)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty access$1700 (Nifty.java:77)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1374)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme handleMouseEvent (InputSystemJme.java:124)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:232)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:296)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: de.lessvoid.nifty.Nifty update (Nifty.java:288)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:113)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.input.InputManager processQueue (InputManager.java:819)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.input.InputManager update (InputManager.java:883)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.app.Application update (Application.java:604)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.app.SimpleApplication update (SimpleApplication.java:231)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:185)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)
ago 03, 2014 9:34:22 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Advertencia: java.lang.Thread run (Thread.java:744)
[/java]

I don’t know why :frowning: , i have check the xml and the java code and its looks right.

[java]
public class MainMenuState extends AbstractAppState implements ScreenController{

private SimpleApplication app;
private AppStateManager stateManager;
private NiftyJmeDisplay jmedisplay;
private Nifty nifty;

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

    //add gui
    jmedisplay = new NiftyJmeDisplay(this.app.getAssetManager(),this.app.getInputManager(),this.app.getAudioRenderer(),this.app.getViewPort());
    jmedisplay.getNifty().fromXml("Interface/mainmenuscreen.xml", "MainMenu");
    nifty = jmedisplay.getNifty();
    this.app.getGuiViewPort().addProcessor(jmedisplay);
    
    
}
@Override
public void update(float tpf) {
    super.update(tpf);
}
  @Override
public void cleanup() {
    super.cleanup(); //To change body of generated methods, choose Tools | Templates.
    this.app.getGuiViewPort().removeProcessor(jmedisplay);
}

public void bind(Nifty nifty, Screen screen) {

}

public void onStartScreen() {
  
}

public void onEndScreen() {
  
}

public void changeScreen(String screen){
    nifty.gotoScreen(screen);
}
public void quit(){
    this.app.stop();
}

}
[/java]

[java]
<?xml version=“1.0” encoding=“UTF-8” standalone=“yes”?>
<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd”>
<useControls filename=“nifty-default-controls.xml”/>
<useStyles filename=“nifty-default-styles.xml”/>
<screen id=“MainMenu” controller=“mygame.MainMenuState” >

    &lt;layer id="GLayer6" backgroundImage="Interface/mainMenuBackground.jpg" childLayout="absolute"&gt;            
        &lt;control name="button" id="newgamebutton" height="7%" backgroundColor="#ffffff32" width="40%" label="New Game" childLayout="center" y="35%"  x="30%" align="center"  visibleToMouse="true"&gt;
            &lt;interact onClick="startGame()"/&gt;
        &lt;/control&gt;
        &lt;control name="button" id="howtoplaybutton" height="7%" backgroundColor="#ffffff32" width="40%" label="How To Play" childLayout="center" y="45%"  x="30%" align="center"  visibleToMouse="true"&gt;
            &lt;interact onClick="changeScreen(HowToPlay)"/&gt;
        &lt;/control&gt;
        &lt;control name="button" id="optionsbutton" height="7%" backgroundColor="#ffffff32" width="40%" label="Options" childLayout="center" y="55%"  x="30%" align="center"  visibleToMouse="true"&gt;
            &lt;interact onClick="changeScreen(OptionsMenu)"/&gt;

        &lt;/control&gt;
        &lt;control name="button" id="scoresbutton" height="7%" backgroundColor="#ffffff32" width="40%" label="Scores" childLayout="center" y="65%"  x="30%" align="center"  visibleToMouse="true"&gt;
            &lt;interact onClick="changeScreen(Scores)"/&gt;
        &lt;/control&gt;
        
        &lt;control name="button" id="creditsbutton" height="7%" backgroundColor="#ffffff32" width="40%" label="Credits" childLayout="center" y="75%"  x="30%" align="center"  visibleToMouse="true"&gt;
            &lt;interact onClick="changeScreen(Credits)"/&gt;
        &lt;/control&gt;
        
        &lt;control name="button" id="quitbutton" height="7%" backgroundColor="#ffffff32" width="40%" label="Quit" childLayout="center" y="85%" x="30%" align="center"   visibleToMouse="true"&gt;  
            &lt;interact onClick="quit()"/&gt;
        &lt;/control&gt;
    &lt;/layer&gt;

&lt;/screen&gt;

&lt;screen id="OptionsMenu" controller="mygame.MainMenuState"  &gt;
    &lt;layer id="GLayer6" backgroundImage="Interface/mainMenuBackground.jpg" childLayout="absolute"&gt;            
      
    &lt;/layer&gt;
&lt;/screen&gt;

&lt;screen id="HowToPlay" controller="mygame.MainMenuState" &gt;
    &lt;layer id="GLayer6" backgroundImage="Interface/mainMenuBackground.jpg" childLayout="absolute"&gt;            
       
    &lt;/layer&gt;
&lt;/screen&gt;

&lt;screen id="Scores" controller="mygame.MainMenuState" &gt;
    &lt;layer id="GLayer6" backgroundImage="Interface/mainMenuBackground.jpg" childLayout="absolute"&gt;            
       
    &lt;/layer&gt;
&lt;/screen&gt;

&lt;screen id="Credits" controller="mygame.MainMenuState" &gt;
    &lt;layer id="GLayer6" backgroundImage="Interface/mainMenuBackground.jpg" childLayout="absolute"&gt;            
       
    &lt;/layer&gt;
&lt;/screen&gt;

</nifty>
[/java]

1 Like

I think
“jmedisplay.getNifty().fromXml(“Interface/mainmenuscreen.xml”, “MainMenu”);” is not right. It should be
“jmedisplay.getNifty().fromXml(“Interface/mainmenuscreen.xml”, “MainMenu”, this);”

See the notice in the middle of this page: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:nifty_gui_scenarios

Otherwise Nifty doesn’t know which screen controller instance to call so it will create a new instance of MainMenuState.

2 Likes

Its work!

Thanks :D!

2 Likes

How about if you create the menu in java code?

I have this

super.initialize(asm, app);
    ms = (SimpleApplication)app;
    
    ourScreen = new NiftyJmeDisplay(app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
   
    nifty = ourScreen.getNifty();
    
    app.getGuiViewPort().addProcessor(ourScreen);
    
    nifty.addScreen("start", new ScreenBuilder("menu"){{
        controller(new mygame.MenuController());
    
        layer(new LayerBuilder("background"){{
            
        childLayoutVertical();
            
            panel(new PanelBuilder("startGame"){{
                
                    childLayoutCenter();
                    width("100%");
                    height("100%");
                    backgroundColor("#000f");    
                    visibleToMouse(true);
                    interactOnClick("startGame()");;
            
            }});
            
        }});
    
    }}.build(nifty));
    
    nifty.gotoScreen("start");

And when I click the panel I get the same error… I have seen the solutions if you create the menu in XML but not in java Code. Is there even a solution?

Thx