[nifty] cant get it to work

hello guys… for (at least) 2 days, i m trying to get a simple example of niftyGUI to work …

i m now seeing what my problem is … my bind method wont be called

furthermore my xml file just cant find my ControllerClass … so i think these problems are linked together…

btw … yeah i searched at this forum and other sources (which took most of the time of these 2 days)

all files are in NiftyGui/src/mygame/

newNiftyGui.xml :

[xml]<screen id=“start” controller=“ControllerTest”>

<layer id=“layer” backgroundColor="#003f" childLayout=“center”>

<panel id=“panel” height=“25%” width=“35%” align=“center” valign=“center” backgroundColor="#f60f" childLayout=“center” visibleToMouse=“true”>

<interact onClick=“quit()”/>


<onStartScreen name=“move” mode=“in” direction=“top” length=“300” startDelay=“0” inherit=“true”/>

<onEndScreen name=“move” mode=“out” direction=“bottom” length=“300” startDelay=“0” inherit=“true”/>

<onHover name=“pulsate” scaleFactor=“0.008” startColor="#f600" endColor="#ffff" post=“true”/>


<text id=“text” font=“aurulent-sans-17.fnt” color="#000f" text=“Quit” align=“center” valign=“center” />






public class ControllerTest implements ScreenController {

NiftyJmeDisplay niftydisplay= null;

Nifty nifty = null;

Screen screen = null;

public ControllerTest(Main game) {

niftydisplay = new NiftyJmeDisplay(





nifty = niftydisplay.getNifty();




public void bind(Nifty nifty, Screen screen) {


this.nifty = nifty;

this.screen = screen;


public void onStartScreen() { System.out.println(“onStart”);}

public void onEndScreen() { }

public void quit() {





and finally



public class Main extends SimpleApplication {

public Nifty nifty;

public ControllerTest myControl;


public void simpleInitApp() {

myControl = new ControllerTest(this);





i tried nearly everthing (the right one wasnt there though)

last thing to say is :

i tried in the xml file several things too like:




or “/” instead of “.”

nothing changed …

the error occure is a classnotfoundexception of ControllerTest

would be REALLY great if someone knock off my stupid lines ^^

thanks in advance!


if i use controller=“mygame/ControllerTest” there is a new error message : NoClassDefFoundException “illegal name”

so there is a problem with my librarys or what else?!


Nifty use the assetmanager from your main class.

The assetmanager store the possible locations of your files. By default, it looks inside the directory “assets” ( if my memory is good )

It’s best to disjoin Java sources from XML data.

I suggest you store your xml files inside a directory below assets.


– src

– assets

– -- xml

Then register the XML path inside your main class


public class Main extends SimpleApplication {

public Nifty nifty;

public ControllerTest myControl;


public void simpleInitApp()


assetManager.registerLocator( “assets/xml/”, FileLocator.class );

myControl = new ControllerTest(this);





For your controller. it’s the name of the whole class name you have to use.

In your file ControllerTest.java, the firsts line should be something like :


package mygame;


public class ControllerTest implements ScreenController {


Then in your xml file, you have to write :


|screen id=“start” controller=“mygame.ControllerTest”|


Warning : it’s case sensitive :slight_smile:

1 Like

in fact i had the package line in my file, but didnt copied it all ^^

i tried ur advices but the problem is still there … seems the xml file doesnt find the controller class

controller= “mygame/ControllerTest” seems to be an illegal name …

so i still dont know what the problem is …

but thx anyway for a try :slight_smile: i m glad there was some1 who actually tried, cuz i dont know anything at all now :slight_smile:

in my opinion i tried everything…except the right one ^^

Sorry, I didn’t see my xml part wasn’t visible.

Did you try “mygame.ControllerTest” ?

i did it, but tried now again :

“12.12.2010 12:19:27 de.lessvoid.xml.tools.ClassHelper getInstance

WARNING: class [mygame.ControllerTest] could not be instanziated (java.lang.InstantiationException: mygame.ControllerTest)”

terry said:
i did it, but tried now again :
"12.12.2010 12:19:27 de.lessvoid.xml.tools.ClassHelper getInstance
WARNING: class [mygame.ControllerTest] could not be instanziated (java.lang.InstantiationException: mygame.ControllerTest)"

The ControllerTest class needs to have an empty constructor.

it worked! thx!

i would have another question if u dont mind:

i m looking for a way to let the main class and the controller classe interact


public Main() {

controller = new ControllerTest();



in simple update()


niftydisplay = new NiftyJmeDisplay(





nifty = niftydisplay.getNifty();





i made something like this and called in the simpleupdate() a method in the controller class like getXYZ()

but it seems this controller i declared and the controller which is actually used are differenet instances, or?

i tried a simple String-changing in the controller and then it should have compared with a string declared in the main class.

it didnt work … so i have to know how it should work … in the other topic there was an example but in fact the setScreenController(controller) didnt worked for me…

anyway, great thx to both of u who helped me out until now!

When you intances a new Nifty it will creator it’s own ScreenController by default.

If you want to use one yuourpreviously created, use this :


nifty.fromXml(“src/mygame/assets/xml/newNiftyGui.xml”,“start”, controller);


the forum was down and i had to look at some other code instead first… and i found just that line u wrote 2hours ago! :smiley:

but thank u very much! to bad the site was down… it would have spared me quite some time.

but dont really understand why the other line didnt work as well… anyway thank u! now i can finally proceed :slight_smile: