In this tutorial (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:nifty_gui_java_interaction) there is the quitGame() method that calls app.stop(); When I run this, it just prints out a ton of WARNING notices to the console, but doesn’t stop the game.
gist:1329006 · GitHub
Anyone have any ideas?
Thanks,
~Jeremy
app.stop() does work. What warnings do you get? Maybe its due to your ruby setup?
Here’s a link to the warnings I’m getting.
https://gist.github.com/1329006
Sadly I couldn’t get it running with ruby So I’m compiling the .java into a .class, and running that… I’m hoping that figuring this out will teach me what I need to know to run it in ruby though.
So does your ScreenController implement the right function, do you supply the right screen controller when creating the nifty object and do you specify the right screen controller class in the XML file? Seems like it cannot find the method.
Yeah, I supply all the stuff. I added a System.out.println("nn CALLING quitGame() nn); and it prints that to the console right before throwing all those warning. My startGame() method that does the nifty.gotoScreen() works fine, no errors, and it goes to the hud screen.
then try/catch any errors that might come after that. Nifty doesn’t pipe them to the output.
I tried this and got “Error: null”
[java]public void quitGame() {
System.out.println(“nn quitGame callednn”);
try {
app.stop();
} catch (Exception e) {
System.out.println("nn Error: " + e.getMessage());
}
}[/java]
e.printStackTrace() is more insightful, probably your app variable is null.
hmm… Yeah, it looks like the same trace as those warnings.
java.lang.NullPointerException
at StartScreenController.quitGame(StartScreenController.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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:1172)
at de.lessvoid.nifty.Nifty.invokeMethods(Nifty.java:1150)
at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:308)
at de.lessvoid.nifty.Nifty.access$1400(Nifty.java:73)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1367)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1325)
at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:123)
at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:192)
at de.lessvoid.nifty.Nifty.update(Nifty.java:244)
at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:92)
at com.jme3.input.InputManager.processQueue(InputManager.java:777)
at com.jme3.input.InputManager.update(InputManager.java:841)
at com.jme3.app.Application.update(Application.java:588)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:235)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)
at java.lang.Thread.run(Thread.java:680)
Now, I’m not passing the app into it. The example just shows creating a new instance of the controller, and using that as the third parameter to
[java]nifty.fromXml(“Interface/screen.xml”, “start”, new StartScreenController());
[/java]
That code is inside my simpleInitApp, so should I be passing “this”? like
[java]nifty.fromXml(“Interface/screen.xml”, “start”, new StartScreenController(this));
[/java]
Thats not the same as the warnings ^^ Yeah, your app variable definitely is null, what you said should work.
effing sweet! I had to change the constructor to take an Application instance instead of a String like in the example, so I hope that doesn’t hinder me later, but other than that, it works! Thanks!!
Btw the ScreenController in the example extends AbstractAppState, there you have access to the app variable by default.