Function not getting called

I have a strange problem in my current code: When I call Controls.requestKeyChange from MenuController.changeControls, it just seems to return from changeControls.

My code:
[java]public class MenuController extends AbstractAppState implements ScreenController{
public void changeControls(String s){
ControlsButton1.setText(“Press any button…”);
System.out.println(“changeControls in MenuController called (Action: “+Controls.Action.values()[Integer.parseInt(s)]+” )”);
Controls.requestKeyChange(Controls.Action.values()[Integer.parseInt(s)], app.getInputManager(), new Runnable() {
public void run() {
[java]public class Controls implements ActionListener{

public static void requestKeyChange(Action action,InputManager im, Runnable executeWhenDone){
    System.out.println("requestKeyChange called (Arguments: "+action+", "+im+", "+executeWhenDone);
    r = executeWhenDone;
    for(int i=0; i<keyCodes.size(); i++){
        im.addMapping(keyNames.get(i), keyboard.get(i) ? new KeyTrigger(keyCodes.get(i)) : new MouseButtonTrigger(keyCodes.get(i)));
    changingControls = true;


Console output:
changeControls in MenuController called (Action: moveUp )
BUILD SUCCESSFUL (total time: 20 seconds)

No errors occur during compilation nor at runtime.

Does anyone know why this happens?

Do you register the screencontroller with nifty?

Yes, and from the console output and the System.out.println call, you see that changeControls is indeed called.

Just a guess…

But if anything in this line:
[java]Controls.requestKeyChange(Controls.Action.values()[Integer.parseInt(s)], app.getInputManager(), new Runnable() {[/java]

throws an exception then Nifty tends to swallow it (in my experience) and execution will stop there. So if app is null you’ll get a swallowed NPE. If the string is not a number you’ll get a swallowed parse exception, etc…

Wrap the whole thing in a try/catch(Exception) to see or put another debug line after it.

I’m not doubting its getting called, but if you don’t register it with nifty, it will create its own instance to manage and it won’t call the instance you thought it would.

I’m just speculating, it might not be the problem, but its a common issue

Actually, looking at the code more analytically, my guess is that app is null and you are just not seeing the NPE that is thrown. It is the only thing that can account for the behavior you are seeing. (Unless you have exactly the same debug println somewhere else and that’s actually what we’re seeing… but I’m assuming that is unlikely. :))

It was indeed an error that was invisible. The app variable was what caused it.

Thanks for your help.