assetManager null after calling nifty.exit

Right, first off, this is my first post. Hi guys!

Ive been reading up and playing with jME3 for the past 3 days. Have been through almost all of the beginner tutorials, and figured its time to dip my foot into the GUI pond.

Ive read the documentation here on it, and have read other peoples posts and tried their code. My problem is that when I close my nifty instance, my assetManager becomes null. I first tried to do this with a more complex world, but now ive slimmed it down and simplified it to a nifty gui and a rotating Geometry box. I can create the gui then the box, but cannot create gui, close gui, create box.



[java]public class Main extends SimpleApplication {

private Geometry box_geo;

private Material box_mat;

private NiftyJmeDisplay niftyDisplay;

public static void main(String[] args) {

Main app = new Main();




public int gameState = 0;

public Nifty nifty;


public void simpleInitApp() {

if (gameState == 0) {









public void loadStartScreen() {

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

nifty = niftyDisplay.getNifty();

nifty.fromXml(“assets/Interface/startscreen.xml”, “start”);

// attach the nifty display to the gui view port as a processor


// disable the fly cam



private void addNewBox(){

if(assetManager == null){

System.out.println(“NULL AM”);


box_mat = new Material(assetManager,“Common/MatDefs/Misc/Unshaded.j3md”);

Texture boxTexture = assetManager.loadTexture(“Interface/Logo/Monkey.jpg”);

box_mat.setTexture(“ColorMap”, boxTexture);

Box box = new Box(Vector3f.ZERO,1f,1f,1f);

box_geo = new Geometry(“Box”,box);






public void simpleUpdate(float tpf){







[java]public class MainGameScreen extends Main implements ScreenController {

public void bind(Nifty nifty, Screen screen) {



public void onStartScreen() { }

public void onEndScreen() { }

public void startGame(){

System.out.println(“DO START”);




public void

quit() {


gameState = 1;




The code has no problem running how it is. It starts with GUI, with rotating cube behind it. Swap the commenting of the addNewBox() in simpleInnitApp and it breaks. I tried it without the call the guiViewPort with the same results. With it, it turns out the guiViewPort is null as well. I feel like ive missed something really small somewhere, and cant for the life of me figure out what it is or where it should go.

Any help appreciated.

EDIT: Even after changing nifty to go to another screen, eveything is still null. Where am I going wrong to kill the assetManager and guiViewPort and stuff? :frowning:

EDIT2: Ok, I did a bit more reading, and remember the third parameter for creating NiftyDisplay. I was using a different instance of a simple application because the controller class in the nifty xml was instantiated fresh so was a different instance. Fixed by either making the class implement SurfaceController and pass in ‘this’, or instantiating the controller class, passing in ‘this’, and then passing that into the NiftyDisplay.