Problem using GUI from other classes then Main()

Hi guys,

just started to work with JME3.

at the moment I try to create the GUI in a own class (for making the Main() easier to read).

At this time it`s just a “healthbar”.

I used the HUDText from the patterns to do this.

Now the Problem:

when i do this from the Main() everything works fine. I then toke it to an HUDcontroller called class, istantiated a HUDController and used it`s Method for updating the HUD.

On starting the game it brakes directly and a null-pointer-exception is thrown:

Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.HUDcontroller.healthMeter(HUDcontroller.java:22)
at mygame.HUDcontroller.showHUD(HUDcontroller.java:35)
at mygame.Main.updateHUD(Main.java:198)
at mygame.Main.simpleUpdate(Main.java:67)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

HUDController line 22 is:

guiFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);

cause its the first line of the exception i think this is the mainpoint of the problem, but i don`t understand why it works from the Main() (its exactly the same line)

is there any way i have to adept this path for the fonts when i dont use it from main?

Thanks for help and greetings from Germany,

Birchwood

Ok, i guess i figured out one part of the Problem, but not enough to fix it:

i thought i needed HUDcontroller to extend SimpleApplication for using the guiNode. Now i read that i never should extend SimpleApplication more then ones(in the Main()) but use the AbstractAppState instead.

reading the AppState chapter in the local help lets me think that this is definetly not the way to go for a simple HUDcontroller.

I now need an idea to use all the thinks the simpleapplication have from an other class.

Pass the stuff you need when you create the object. Simple basic Java stuff, really.