Hello everybody
I have a serious issue with Nifty: I have a basic authentication panel, that sends the name to a server that checks if it’s available or not. Problem: I often get a null pointer exception right after I click on the submit button. Has anyone an idea on what is wrong here…? In advance, thanks for your time and your answers XD
Sources:
[java]
private ListBox<String> faction_alliance;
private ListBox<String> faction_rebelle;
public void sendName() {
login = nifty.getScreen(“connect”).findNiftyControl(“login”, TextField.class).getText();
NameMessage message = new NameMessage(login, true); //sends the login and a boolean. If the name is available, the server sends back the
game.getClient().send(message); //message without editing it. If it’s not, the server sets the boolean to false and a popup appears
}
public void messageReceived(Client source, final Message m) {
if(m instanceof NameMessage) {
NameMessage message = (NameMessage) m;
if(message.getOk() == true) {
factionPanel();
FactionMessage fa = new FactionMessage(); //sends a message to the server to get current players. If there are no players, the client doesn't get any answer
game.getClient().send(fa);
}
else if (message.getOk() == false) {
createMyPopupMenu("Name already in use");
nifty.showPopup(nifty.getCurrentScreen(), popup.getId(), null);
}
}
if (m instanceof FactionMessage) {
FactionMessage message = (FactionMessage) m;
System.out.println("message received " + message.getName());
if(nifty.isActive("Interface/accueil.xml", "choice_faction")) {
if(message.getFaction() == 1) {
faction_alliance.addItem(message.getName()); //Answers of the server if there are players actually playing. Their names are added to the ListBox of their faction
}
else if(message.getFaction() == 2) {
faction_rebelle.addItem(message.getName()); //Same process
}
}
}
}
public void factionPanel() {
nifty.gotoScreen("choice_faction");
faction_alliance = nifty.getCurrentScreen().findNiftyControl("listBoxStatic1", ListBox.class); //adds 2 ListBox to the screen (empty if there are no players)
faction_alliance.addItem("Alliance");
faction_rebelle = nifty.getCurrentScreen().findNiftyControl("listBoxStatic2", ListBox.class);
faction_rebelle.addItem("Rebelle");
}[/java]
And the XML:
[java]
<screen id=“connect” controller=“mygame.NiftyGui”>
<layer id=“background” backgroundImage=“Interface/gui-background.png”>
</layer>
<layer id=“log” childLayout=“vertical”>
<panel id="panel1" height="60%" width="50%" align="center" valign="center" childLayout="center">
<text text="Login" font="Interface/Fonts/Default.fnt" width="50%" height="50%" wrap="false" color="#FF1302"/>
</panel>
<panel id="panel2" height="-10%" width="100%" valign="center" childLayout="center">
<control name="textfield" id="login" width="15%" />
</panel>
<panel id="panel3" height="30%" width="100%" valign="center" childLayout="center">
<control name="button" label=" Submit " id="submit" align="center" valign="center" visibleToMouse="true">
<interact onClick="sendName()"/>
</control>
</panel>
</layer>
</screen>
//////////////////////////////////////////////////////////////////////////////
<screen id="choice_plane" controller="mygame.NiftyGui">
<layer id="background" backgroundImage="Interface/gui-background.png">
</layer>
<layer id="couche1" childLayout="vertical" >
<panel id="panel_top" height="80%" width="100%" valign="center" childLayout="center">
<control name="button" label="Avion 1" id="plane1" align="center" valign ="center" visibleToMouse="true" >
<interact onClick="choicePlane(p1)"/>
</control>
</panel>
<panel id="panel_top" height="-40%" width="100%" valign="center" childLayout="center">
<control name="button" label="Avion 2" id="plane2" align="center" valign ="center" visibleToMouse="true" >
<interact onClick="choicePlane(p2)"/>
</control>
</panel>
</layer>
<layer id="couche2" childLayout="vertical" >
<panel id="panel_bottom_left" height="60%" width="40%" valign="center" childLayout="center">
<image filename="Interface/pyramid.jpg" height="190px" id="image1" width="199px" />
</panel>
<panel id="panel_bottom_right" height="20%" width="40%" valign="center" childLayout="center">
<image filename="Interface/cube.jpg" height="190px" id="image2" width="199px" />
</panel>
</layer>
</screen>
[/java]
Finally, the error:
[java]
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at de.lessvoid.nifty.elements.Element.canHandleInteraction(Element.java:1474)
at de.lessvoid.nifty.elements.Element.mouseEvent(Element.java:1405)
at de.lessvoid.nifty.screen.MouseOverHandler.processMouseEvent(MouseOverHandler.java:101)
at de.lessvoid.nifty.screen.Screen.forwardMouseEventToLayers(Screen.java:360)
at de.lessvoid.nifty.screen.Screen.mouseEvent(Screen.java:336)
at de.lessvoid.nifty.Nifty.forwardMouseEventToScreen(Nifty.java:266)
at de.lessvoid.nifty.Nifty.access$1400(Nifty.java:73)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1370)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1329)
at com.jme3.niftygui.InputSystemJme.onMouseMotionEventQueued(InputSystemJme.java:186)
at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:258)
at de.lessvoid.nifty.Nifty.update(Nifty.java:248)
at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:113)
at com.jme3.input.InputManager.processQueue(InputManager.java:821)
at com.jme3.input.InputManager.update(InputManager.java:885)
at com.jme3.app.Application.update(Application.java:606)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:230)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)
[/java]
Wow… That’s a massive post, sorry