Nifty callback function

I have followed the tutorial to get nifty running its great. On the push of a button i have it working to print out you pushed a button but i want it to call a function in the main class to login. Im not sure how todo this when i try to implement it i get “non-static method gamemode() cannot be referenced from a static context”. I have my class MainMenuController that handles the button click then i want it to call gamemode on my Main class. I know this is something todo with object oriented ness can some one tell me the right way todo this or atleast a way to achieve my desired result. Thank you

I haven’t use the nifty part of jme yet but it does just sound like an oo problem. If you posted code it would be easy to give you the fix but you either need to make that method static or remove the context you are using in it from being static. If I had to guess you will need to declare gamemode

[java]public static void gamemode()[/java]

well see the problem with that is whenever i try to do somthing on the root node like rootNode.detachAllChildren(); i get non-static variable rootNode cannot be referenced from a static context. Ill try to post the relevant code.


public class Main exstends SimpleApplication {

public void gamemode(){


//does other crap but not relavant



public class MainMenuController implements ScreenController {

public void buttonpush(){

System.out.println(“button pushed”); //works just fine

Main.gamemode(); //cant call because not static




Well by some miracle i got it working ill try to explain how for the next guy.

instead of my main class being the game i made a specific game class

my main class creates a new game class lets say g

then on a click the MainMenuController class button push gets called that does Main.g.gamecode();

and that seemed to do the trick.