Trouble with Nifty, calling java methods

Is this the only xml-file you're using?

I don't see your custom control being used in the xml, do you add it in code?

If so, how does that code look?

Is the RegistrationPanelController implementing Controller and LoginScreenController implementing ScreenController (although you write that LoginScreenController doesn't exist, is loginScreen your start screen?)?

How does your RegistrationPanelController look?

Are you using the latest version from svn?



Edit: Sorry about asking so many questions, but they might help to investigate the problem. :slight_smile:

OK, let me try and answer those questions…



Yes this is the only xml I'm using at this time.



I have the LoginScreenController implementing ScreenController. This is the main screen. In this screen I have a method addRegistrationPanel which I call from the register button on the main login screen.

This method adds the RegistrationPanelController to the box-parent panel. The code I use for this is:


CustomControlCreator createRegistrationPanel = new CustomControlCreator("registrationPopUpPanel", "registrationPanelControl");
        createRegistrationPanel.create(nifty, screen, screen.findElementByName("box-parent"));



The RegistrationPanelController implements Controller.

I am using the version in the JME3 nightly build frmo friday.

Let me add the full souce code for my three classes:


package com.ractoc.opengamefinder.client.screens;

import com.jme3.app.SimpleApplication;
import com.jme3.niftygui.NiftyJmeDisplay;

import de.lessvoid.nifty.Nifty;

public class LoginScreen extends SimpleApplication {

    private Nifty nifty;

    public void simpleInitApp() {
        NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                          inputManager,
                                                          audioRenderer,
                                                          guiViewPort);
        nifty = niftyDisplay.getNifty();

        nifty.fromXml("configuration/nifty/login.xml", "start");

        // attach the nifty display to the gui view port as a processor
        guiViewPort.addProcessor(niftyDisplay);

        // disable the fly cam
        flyCam.setDragToRotate(true);
    }

}





package com.ractoc.opengamefinder.client.screens.controllers;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.dynamic.CustomControlCreator;
import de.lessvoid.nifty.controls.textfield.controller.TextFieldControl;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 * StartScreenController for Multiplayer.
 *
 * @author void
 */
public class LoginScreenController implements ScreenController {
    private Nifty nifty;
    private Screen screen;
   
    private int id = 1000;
   
    public void bind(final Nifty newNifty, final Screen newScreen) {
        this.nifty = newNifty;
        this.screen = newScreen;
    }

    public void onStartScreen() {
        System.out.println("Starting screen");
    }

    public void onEndScreen() {
        System.out.println("Ending screen");
    }
   
    public void quit() {
        System.out.println("quiting");
        System.exit(0);
    }

    public void login() {
        System.out.println("logging in");
        final TextFieldControl nameControl = screen.findControl("name", TextFieldControl.class);
        final String name = nameControl.getText();
        final TextFieldControl passwordControl = screen.findControl("password", TextFieldControl.class);
        final String password = passwordControl.getText();
        System.out.println("name: " + name);
        System.out.println("password: " + password);
    }

    public void addRegistrationPanel() {
        System.out.println("adding registration panel");
        CustomControlCreator createRegistrationPanel = new CustomControlCreator("registrationPopUpPanel", "registrationPanelControl");
        createRegistrationPanel.create(nifty, screen, screen.findElementByName("box-parent"));
    }
}





package com.ractoc.opengamefinder.client.screens.controllers;

import java.util.Properties;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.Controller;
import de.lessvoid.nifty.controls.textfield.controller.TextFieldControl;
import de.lessvoid.nifty.elements.ControllerEventListener;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.input.NiftyInputEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.xml.xpp3.Attributes;

public class RegistrationPanelController implements Controller {
    private Nifty nifty;
    private Screen screen;
    private Element element;

    public void bind(
        final Nifty niftyParam,
        final Screen screenParam,
        final Element newElement,
        final Properties properties,
        final ControllerEventListener newListener,
        final Attributes controlDefinitionAttributes) {
      nifty = niftyParam;
      screen = screenParam;
      element = newElement;
    }

    @Override
    public void onStartScreen() {
    }

    public void onFocus(final boolean getFocus) {
    }

    public void inputEvent(final NiftyInputEvent inputEvent) {
    }

    public void register() {
        System.out.println("Registering");
        final TextFieldControl nameControl = screen.findElementByName("registrationPanel").findControl("name", TextFieldControl.class);
        final String name = nameControl.getText();
       
        System.out.println("name: " + name);
    }

    public void back() {
        System.out.println("Not registering");
        nifty.removeElement(screen, element);
    }

}



There, now you have everything but the startup class, but that one whould be simple to recreate...

Replacing:


...screen.findElementByName("registrationPanel")...


with:

...screen.findElementByName("registrationPopUpPanel")...


will probably work better :)

Well, it probably would be more friendly when Nifty directly complains with a ElementNotFoundException or something when elements could not be found :/

Currently your register() method has thrown a NPE that made it seems that the method call itself failed.

Great, that fixed my problem… Stupid mistake on my part.



Anyway, this project will have to go on a back burner for a while, as will my other project.

Just become a dad for the second time yesterday  :smiley: :smiley: :smiley: :D, so my time is better spent doing something else for a while…

Congratulations! :slight_smile: