Nifty popupmenu not working

Hello,



This is the error when trying to run my testapplication:



java.lang.NullPointerException

at de.lessvoid.nifty.loaderv2.types.XmlBaseType.(XmlBaseType.java:15)

at de.lessvoid.nifty.loaderv2.types.ElementType.(ElementType.java:40)

at de.lessvoid.nifty.loaderv2.types.PopupType.(PopupType.java:14)

at de.lessvoid.nifty.Nifty.createPopupFromType(Nifty.java:806)

at de.lessvoid.nifty.Nifty.createAndAddPopup(Nifty.java:859)

at de.lessvoid.nifty.Nifty.createPopup(Nifty.java:834)

at mygame.NiftyPopupTest.simpleInitApp(NiftyPopupTest.java:48)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)



the code

[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;



/**

  • test
  • @author normenhansen

    */

    public class NiftyPopupTest extends SimpleApplication implements ScreenController {



    private Nifty nifty;

    private Screen screen;

    //private SimpleApplication app;



    public static void main(String[] args) {

    NiftyPopupTest app = new NiftyPopupTest();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry(“Box”, b);



    Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat.setColor(“Color”, ColorRGBA.Blue);

    geom.setMaterial(mat);



    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort);

    nifty = niftyDisplay.getNifty();



    nifty.addXml(“Interface/screens/screenGame.xml”);

    // nifty.addXml(“Interface/screens/screenOptions.xml”);

    // nifty.addXml(“Interface/screens/screenStart.xml”);

    nifty.gotoScreen(“start”);



    nifty.createPopup(“popupExit”);

    nifty.showPopup(screen, “popupExit”, null);



    guiViewPort.addProcessor(niftyDisplay);

    inputManager.setCursorVisible(true);

    rootNode.attachChild(geom);

    }



    @Override

    public void simpleUpdate(float tpf) {

    //TODO: add update code

    }



    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }



    public void onStartScreen() {

    }



    public void onEndScreen() {



    }



    public void gotogame() {

    nifty.gotoScreen(“game”);

    }



    public void gotooptions() {

    nifty.gotoScreen(“options”);

    }



    public void gotostart() {

    nifty.gotoScreen(“start”);

    }



    public void quitGame() {

    this.stop();

    }



    public void bind(Nifty nifty, Screen screen) {



    this.nifty = nifty;

    this.screen = screen;



    }

    }



    [/java]

    And the xml

    [xml]

    <?xml version=“1.0” encoding=“UTF-8”?>

    <nifty xmlns=“http://nifty-gui.sourceforge.net/nifty.xsd” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

    xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty.xsd http://nifty-gui.sourceforge.net/nifty.xsd”>

    <useControls filename=“nifty-default-controls.xml” />

    <useStyles filename=“nifty-default-styles.xml” />

    <screen id=“start” controller=“mygame.NiftyPopupTest”>

    <layer id=“foreground” backgroundColor="#0000" childLayout=“vertical”>



    <panel id=“panel_top” height=“10%” width=“100%” valign=“top” childLayout=“center”>

    <control name=“button” label=“Game” id=“MainButton” align=“center” valign=“top” visibleToMouse=“true”>

    <interact onRelease =“gotogame()” />

    </control>

    </panel>



    <panel id=“panel_top2” height=“10%” width=“100%” valign=“top” childLayout=“center”>

    <control name=“button” label=“Options” id=“OptionsButton” align=“center” valign=“top” visibleToMouse=“true”>

    <interact onRelease = “gotooptions()” />

    </control>

    </panel>



    <panel id=“panel_top_mid” height=“10%” width=“100%” valign=“top” childLayout=“center”>

    <text text=“Startscreen” font=“Interface/Fonts/Default.fnt” width=“100%” height=“5%” />

    </panel>



    </layer>



    <popup id=“popupExit” childLayout=“center” backgroundColor="#000a">

    <panel id=“panel_bottem” height=“70%” width=“100%” valign=“top” childLayout=“center”>

    </panel>

    </popup>



    </screen>

    </nifty>

    [/xml]



    I’m running the latest stable jmp, also tried “nifty-default-controls-1.3.1-20110716.000234-9.jar” see http://hub.jmonkeyengine.org/groups/gui/forum/topic/niftypopupmenu-events/

    => Same error



    Anyone has nifty popupmenus working with the current version?

Nope, I’m having the same problems. I hope to talk to void about this tonight.

That would be great, please keep us informed

your xml is not valid. move the popup out of the screen. nifty.validateXml(file) should help as well.

Strange things here



Ive tried this xml just for testing

[xml]<?xml version="1.0" encoding="UTF-8"?>

<nifty xmlns="http://nifty-gui.sourceforge.net/nifty.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty.xsd http://nifty-gui.sourceforge.net/nifty.xsd">

<useControls filename="nifty-default-controls.xml" />

<useStyles filename="nifty-default-styles.xml" />

<screen id="start" controller="mygame.NiftyPopupTest">

<layer id="foreground" backgroundColor="#1009" childLayout="vertical">

</layer>

</screen>

<popup id="popupExit" backgroundColor="#0ee9" childLayout="center">

<panel id="panel_bottem" height="100%" width="100%" valign="top" childLayout="center">

<control name="button" label="but1" id="Button1" align="center" valign="top" visibleToMouse="true">

<interact onRelease = "gotooptions()" />

</control>

</panel>

</popup>

</nifty>[/xml]

Not working, the popup is not showing.

Then i tried to use validateXml like this:

[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;

import java.util.logging.Level;

import java.util.logging.Logger;



/**

  • test
  • @author normenhansen

    */

    public class NiftyPopupTest extends SimpleApplication implements ScreenController {



    private Nifty nifty;

    private Screen screen;

    //private SimpleApplication app;



    public static void main(String[] args) {

    NiftyPopupTest app = new NiftyPopupTest();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry(“Box”, b);



    Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat.setColor(“Color”, ColorRGBA.Blue);

    geom.setMaterial(mat);



    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort);

    nifty = niftyDisplay.getNifty();



    // nifty.addXml(“Interface/screens/screenGame.xml”);

    // nifty.addXml(“Interface/screens/screenOptions.xml”);

    nifty.addXml(“Interface/screens/screenStart.xml”);

    try {

    nifty.validateXml(“Interface/screens/screenStart.xml”);

    } catch (Exception ex) {

    Logger.getLogger(NiftyPopupTest.class.getName()).log(Level.SEVERE, null, ex);

    }



    nifty.gotoScreen(“start”);



    nifty.createPopup(“popupExit”);

    nifty.showPopup(screen, “popupExit”, null);

    //Element exitPopup = nifty.createPopup(“popupExit”);

    //nifty.showPopup(screen, exitPopup.getId(), null);





    guiViewPort.addProcessor(niftyDisplay);

    inputManager.setCursorVisible(true);

    rootNode.attachChild(geom);

    }



    @Override

    public void simpleUpdate(float tpf) {

    //TODO: add update code

    }



    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }



    public void onStartScreen() {

    }



    public void onEndScreen() {



    }



    public void gotogame() {

    nifty.gotoScreen(“game”);

    }



    public void gotooptions() {

    nifty.gotoScreen(“options”);

    }



    public void gotostart() {

    nifty.gotoScreen(“start”);

    }



    public void quitGame() {

    this.stop();

    }



    public void bind(Nifty nifty, Screen screen) {



    this.nifty = nifty;

    this.screen = screen;



    }

    }

    [/java]



    but this gives me the following error:



    SEVERE: null

    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘nifty’.

    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)

    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)

    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)

    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)

    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1916)

    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)

    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:273)

    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:240)

    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:186)

    at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:104)

    at javax.xml.validation.Validator.validate(Validator.java:127)

    at de.lessvoid.nifty.loaderv2.NiftyLoader.validate(NiftyLoader.java:85)

    at de.lessvoid.nifty.loaderv2.NiftyLoader.validateNiftyXml(NiftyLoader.java:64)

    at de.lessvoid.nifty.Nifty.validateXml(Nifty.java:501)

    at mygame.NiftyPopupTest.simpleInitApp(NiftyPopupTest.java:49)

    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)

    at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

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

    at java.lang.Thread.run(Thread.java:662)

    1-dec-2011 22:27:13 de.lessvoid.nifty.Nifty gotoScreen

    INFO: gotoScreen [start]

If you’re using a current version of jme3 with Nifty 1.3 you need to use the correct namespace in your XML file.



the correct one is (without the < and > chars because they f*cked up the forum):



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”



you can find it explained on the Nifty blog as well: http://nifty-gui.lessvoid.com/archives/241

1 Like

I found that info just before you posted it :slight_smile:



Okey at least my xml is validated correctly now but the popup is still not showed.



I’ve used 2 different ways:



1.

[java]

public class NiftyPopupTest extends SimpleApplication implements ScreenController {



private Nifty nifty;

private Screen screen;

private Element exitPopup;

//private SimpleApplication app;



public static void main(String[] args) {

NiftyPopupTest app = new NiftyPopupTest();

app.start();

}



@Override

public void simpleInitApp() {

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry geom = new Geometry(“Box”, b);



Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Blue);

geom.setMaterial(mat);



NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort);

nifty = niftyDisplay.getNifty();



// nifty.addXml(“Interface/screens/screenGame.xml”);

// nifty.addXml(“Interface/screens/screenOptions.xml”);

nifty.addXml(“Interface/screens/screenStart.xml”);

try {

nifty.validateXml(“Interface/screens/screenStart.xml”);

} catch (Exception ex) {

//Logger.getLogger(NiftyPopupTest.class.getName()).log(Level.SEVERE, null, ex);

}





nifty.gotoScreen(“start”);



// nifty.createPopup(“popupExit”);

// nifty.showPopup(screen, “popupExit”, null);

exitPopup = nifty.createPopup(“popupExit”);

nifty.showPopup(screen, exitPopup.getId(), null);





guiViewPort.addProcessor(niftyDisplay);

inputManager.setCursorVisible(true);

rootNode.attachChild(geom);

}

[/java]



This is giving me following error:

java.lang.NullPointerException

at de.lessvoid.nifty.Nifty.showPopup(Nifty.java:799)

at mygame.NiftyPopupTest.simpleInitApp(NiftyPopupTest.java:61)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

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

at java.lang.Thread.run(Thread.java:662)



Then i tried a different way like this:

[java]

nifty.createPopup(“popupExit”);

nifty.showPopup(screen, “popupExit”, null);

// exitPopup = nifty.createPopup(“popupExit”);

// nifty.showPopup(screen, exitPopup.getId(), null);

[/java]



Now i dont get an error but the popupwindow is not showed on the screen, i still use the same xml from my first post except for the namespace correction and the popup outside of screen:



[xml]

<?xml version=“1.0” encoding=“UTF-8”?>

<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=“start” controller=“mygame.NiftyPopupTest”>

<layer id=“foreground” backgroundColor="#1009" childLayout=“vertical”>

</layer>

</screen>



<popup id=“popupExit” backgroundColor="#0ee9" childLayout=“center”>

<panel id=“panel_bottem” height=“100%” width=“100%” valign=“top” childLayout=“center”>

<control name=“button” label=“but1” id=“Button1” align=“center” valign=“top” visibleToMouse=“true”>

<interact onRelease = “gotooptions()” />

</control>

</panel>

</popup>

</nifty>





[/xml]

Now i do see this:



INFO: Child (BitmapFont) attached to this node (null)

1-dec-2011 23:32:11 de.lessvoid.nifty.NiftyStopwatch stop

INFO: [0009] RenderDevice.createFont(aurulent-sans-16.fnt)

1-dec-2011 23:32:11 de.lessvoid.nifty.Nifty showPopup

WARNING: missing popup [popupExit] o_O

1-dec-2011 23:32:11 com.jme3.scene.Node attachChild

INFO: Child (Box) attached to this node (Root Node)





Missing popup? it is there in my xml

The first way is right. The second way is wrong (and therefore gives you the error in the log).



I think the main problem is, that Nifty will create a new instance of your class “mygame.NiftyPopupTest” as the ScreenController for your screen. So in this new instance the screen variable is being set correctly in bind() but in your original instance the screen variable is still null and therefore gives you a NPE.



You might want to verify this and output the content of screen to the log right before you try to show the popup.



If you can confirm this then I see two possible solution:



a. you move the call of the showPopup method to the correct instance of the ScreenController or

b. you tell Nifty about your instance using nifty.registerScreenController(this) before you call nifty.addXml()



good luck! :slight_smile:

1 Like

now i tried :

[java]

private Element exitPopup;

exitPopup = nifty.createPopupWithId("popupExit", "popupExit");

[/java]



Still no luck



java.lang.NullPointerException

at de.lessvoid.nifty.Nifty.showPopup(Nifty.java:799)

at mygame.NiftyPopupTest.simpleInitApp(NiftyPopupTest.java:64)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

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

at java.lang.Thread.run(Thread.java:662)

I did as you said,



[java]

nifty.registerScreenController(this);

nifty.addXml("Interface/screens/screenStart.xml");

[/java]



And eureka :slight_smile:



Thankyou very much for this lesson.

Hello all ,
I have a problem with popup nifty menu , I created an environment using Google Sketchup , I succeeded in rendering the environment and walking through it and everything is working , the problem came when I tried to pop up a menu when the user clicks on the environment , I faced an Null-pointer exception but I read all the comments and now there is no exception but the popup menu is not rendering … any Ideas of how can I solve this ??

Any help would be greatly appreciated,
Thanks for advanced