Exception when trying to create NiftyGUI

Hello,



when trying to create a nifty gui like in the tutorials, I get following exception:

java.lang.NoClassDefFoundError: de/lessvoid/nifty/spi/render/MouseCursor



It points to following line:

[java] NiftyJmeDisplay guiDisplay = new NiftyJmeDisplay(assetManager, inputManager,

audioRenderer, guiViewPort);[/java]



What’s the problem?

You probably miss some library, are you using jMP?

Yes, I am using jMP.

Did you clean & build the project some time after the latest updates? Did you change the default library configuration for your project?

It works now.



Is there a way to display my hud images behind my nifty elements? Because with the normal method my hud images are rendered over my nifty elements.

Is the button control working? control name=“button” … />



Because I get a java.lang.IllegalArgumentException: Can’t subscribe to null.



when trying to create a button that way.

Please post your entire screen xml and I’ll have a look.

you should get a regular warning from nifty in the log when you’re trying to create controls without an id that use the event bus notification.



please give your button (and all other controls) an id. something like: "… name=“button” id=“mybutton” … and the message will go away. when creating controls from java via the Builder stuff then the controls should automatically get ids (iirc that is :slight_smile:

Ah ok, will do. That fixed my button.

Is the onClick for controls working yet?



Here is my button:



[xml]

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

<nifty>

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

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

<screen id=“start” controller=“tests.test02.TestGui”>

<layer id=“0” backgroundColor="#00000000" childLayout=“vertical”>

<control name=“button” id=“btn_0” label=“Test” height=“2%” width=“15%” align=“center”>

<interact onClick=“testPrintln()” />

</control>

</layer>

</screen>

</nifty>

[/xml]



But the testPrintln(), which prints “test” on the console, isn’t being called when I click on the button.



Also, how can I align multiple elements at the vertical and horizontal center of the screen?

is testPrintln() a public method on your class tests.test02.TestGui ?

anything in the log?



your xml looks ok …

It tells me it can’t instanziate the controller class, because it got a class not found exception.



If I use the same string in an import statement, it can find the class without problems, however. So the packages + class names are right.

I’d suspect that this class not found exception is the cause for your method not being called then >_<



can you post the exception please? nifty does not do anything unusual to load the class just a:



[java]Class < ? > cls = ClassHelper.class.getClassLoader().loadClass(className);[/java]



and it checks if this class implements ScreenController but that’s it.



maybe some odd issue with jmp or a typo somewhere? o_O

Ok, now I got it.



It can’t load inner classes and it needs a default constructor.

It can load inner classes and if you tell Nifty about your ScreenController instances (the ones you have instantiated) it can even use a ScreenController without a default constructor.

What does a “NoSuchElementException” mean when it points to: gui.fromXml(“Interface/gui.xml”, “start”); ?



Does that mean it can’t find “start”?

myamo said:
It works now.


How did you fix it? Got the same problem :/

edit: cancel that, just noticed the new sdk on the frontpage, everything fine now, too

can you post the whole stacktrace please? NoSuchElementException can really mean everything …

It begins at this line:



[java]

gui.fromXml(“Interface/gui.xml”, “start”);

[/java]



and then goes up:



[java]

java.util.NoSuchElementException

at java.util.AbstractList$Itr.next(AbstractList.java:350)

at de.lessvoid.nifty.loaderv2.types.ControlType.makeFlatControlsInternal(ControlType.java:67)

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

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

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

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

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

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

at de.lessvoid.nifty.loaderv2.types.ScreenType.create(ScreenType.java:64)

at de.lessvoid.nifty.loaderv2.types.NiftyType.create(NiftyType.java:137)

at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:468)

at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:369)

[/java]



My gui is showing and working. But it bugs me nevertheless.



Oh and, can I add items to a DropDown only through my code or is it possible to do it in the xml as well?

Read the documentation? (You’re lucky, there is actually one for the DropDown :wink:



http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Standard_Controls_DropDown



Adding items from XML is not supported anymore in Nifty 1.3. You’ll need to use Java for it.





Can you send your “gui.xml” too? I think there is an error in the xml somewhere that causes this Exception…