Okay, so another t0neg0d GUI. So I heard t0neg0d’s plea, and decided to use a single screen per AppState. Simple enough. In my main menu state, I have a screen, and I add a button. Then, when the button is hit, it switches to the LevelState, where a new screen is being created. Only problem is, I get a null pointer exception on that line, and I’m not sure what is null…
Here is the MainMenuState:
[java]public class MainMenuState extends AbstractAppState {
AppStateManager stateManager;
SimpleApplication app;
Screen screen;
Node guiNode;
Node rootNode;
@Override
public void initialize(final AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.stateManager = stateManager;
this.app = (SimpleApplication)app;
this.rootNode = this.app.getRootNode();
this.guiNode = this.app.getGuiNode();
screen = new Screen(this.app);
guiNode.addControl(screen);
ButtonAdapter start_button = new ButtonAdapter(screen,"panel", new Vector2f(15, 15)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
stateManager.detach(Main.main_menu_state);
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
start_button.setText("hello");
//panel.hide();
screen.addElement(start_button);
app.getInputManager().setCursorVisible(true);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
}
@Override
public void update(float tpf) {
//TODO: implement behavior during runtime
}
@Override
public void cleanup() {
super.cleanup();
guiNode.removeControl(screen);
stateManager.attach(Main.level_state);
//screen.r
//guiNode.detachAllChildren();
//TODO: clean up what you initialized in the initialize method,
//e.g. remove all spatials from rootNode
//this is called on the OpenGL thread after the AppState has been detached
}
}[/java]
And then here is up to the line where the error occurs:
[java]public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
System.out.println(app);
this.app = (SimpleApplication)app;
this.stateManager = stateManager;
this.assetManager = this.app.getAssetManager();
this.cam = this.app.getCamera();
this.rootNode = this.app.getRootNode();
this.guiNode = this.app.getGuiNode();
generalSetup();
setupPlayer();
//createMappings();
rxf = new ReadXMLFile("Textures/testMap.tmx",assetManager,bas);
rxf.parse();
l = rxf.createLevel(cam);
rootNode.attachChild(l);
setupCollidables();
createMappings();
game_timer = new LwjglTimer();
System.out.println(this.app);
Screen screen = new Screen(this.app);[/java]
Pretty simple, I think. Create a screen, wait for the button to get hit, detach the state, cleanup by removing the screen control and attaching the new state. In new state, create new screen. Where is something null? The System.out.println(this.app) doesn’t return nulll, so … help?