Add Controls in Nifty GUI .xml

Hello, so I have created a project in JME3 and now I am looking at the menu. I have created an .xml file and can se a basic menu, And in the tutorial it says that you must load a Control Definition.

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

The problem is that I am working in a maven project. And to load my GUI I do the following:

app.getAssetManager().registerLocator("assets.zip", ZipLocator.class);
nifty.fromXml("assets/MainMenu.xml", "start");

And when I run this I get a NullPointerException at nifty.fromXml(…). I am asuming that they cannot find the files for the styles and the controls when the xml is in the assets.zip file. How do I write in the .xml when it is in a .zip file? (The assets.zip is in the rootfolder of the project).

Is it getting a null pointer exception because you attempt to load MainMenu.xml and it can’t find it or that it can’t find the styles? If you can’t find the styles I would assume that you don’t have the nifty jar added to your project that contains them.

FYI: without a stack trace, you might as well not even mention the exception at all since you left out 95% of the important information.

assets.jar is on the classpath btw, no need to specifically mention it.

Edit: Oh, you’re using your own setup, never mind.

I’m not sure about using Maven, but before you do a nifty.fromXML you should use:

nifty.loadStyleFile("nifty-default-styles.xml");
nifty.loadControlFile("nifty-default-controls.xml");

The nifty defaults are not stored in assets, they’re in the libraries nifty-default-styles.jar and nifty-default-controls.jar

If you have custom styles and/or controls load them second:

nifty.loadStyleFile("Interface/Styles/nifty-custom-styles.xml");
nifty.loadControlFile("Interface/Controls/nifty-custom-controls.xml");

Loading custom styles and controls second ensures that any custom styles/controls that override the defaults are used instead of the default.

Nifty uses a Map to store and reference styles & controls so loading a custom style/control with the same name as a default will just replace the loaded default in the Map.

I don’t know how you package your assets folder but if you have to prefix your asset paths with “assets/” it looks to me as if something is wrong there. Like your project folder is on the classpath when you run from your IDE, hence you think using the assets prefix is a good idea and then you package the actual contents of your assets folder in the zip or something but in any case its a homemade problem you’ll have to fix in your own kitchen :slight_smile: