Nifty Basics

I’ve been trying to follow the example at https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:nifty_gui



I have copy+pasted code directly from it, and it still does not work for me.


niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
nifty = niftyDisplay.getNifty();

try {
nifty.validateXml("niftyGUI/NiftyGUI.xml");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}

nifty.fromXml("niftyGUI/NiftyGUI.xml", "start", screenController);

guiViewPort.addProcessor(niftyDisplay);
inputManager.setCursorVisible(true);


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



















The error I get is

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

Changing nifty.validateXml("niftyGUI/NiftyGUI.xml"); to a different file address gives a different error, so it IS finding the file correctly.

I have also looked at several forum links which did not help me, such as http://hub.jmonkeyengine.org/groups/gui/forum/topic/if-nifty-were-flammable-itd-be-ashes-by-now/ http://hub.jmonkeyengine.org/groups/gui/forum/topic/missing-screencontoller/ http://hub.jmonkeyengine.org/groups/gui/forum/topic/nifty-popupmenu-not-working/

What am I doing wrong?

The XML didn’t post right, so I put it on pastebin. http://pastebin.com/G6vA39Yz

You’re missing the schema declarations on the nifty-tag:

[xml]<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”>[/xml]

Without those an xml validator wouldn’t know where to find the “rules” for how the xml file should be structured.



Edit: Ignore the -tags, they seem to be automatic even inside [xml][/xml]-tags.

That worked, thanks. In case anyone else was having the same problem, the updated xml file is at http://pastebin.com/kPxS4Sa4



Does this mean that I have to be able to connect to the internet to start my program? What if I want it to work offline?

There should be an xsd-file in the nifty source as well and you can use that one instead, offline, if you like.

Of course you should then point your xml-file to that xsd-file instead of to the online URL.

There’s no need to validate the xml file to run nifty though, it’s just to make sure it’s correctly formatted.

Here’s some info on xml schemas (xsd’s): http://www.w3schools.com/schema/default.asp