Greetings Monkies.
Im having trouble with nifty again… This time an evil nullpointer Exception of death occures
The Debugoutput i made states, that all TextFields and the Spatial itself isn’t null. I ven tried using setText with static Strings… But it wont work. So i guess the mistakte lies at setText().
I know, that the TextFieldControl class is deprecated but i couldnt find its substitute? How can i access TextFields and stuff if not in this way? I couldnt really find it. Am i blind? oô
The aching method:
[java]
private void updateModelEditScreen(Spatial S) {
if (S==null) throw new RuntimeException(“Error: Null Spatial in updateModelEditScreen.”);
toEdit=S;
TextFieldControl PX=nifty.getScreen(“ModelEdit”).findControl(“PosX”, TextFieldControl.class);
TextFieldControl PY=nifty.getScreen(“ModelEdit”).findControl(“PosY”, TextFieldControl.class);
TextFieldControl PZ=nifty.getScreen(“ModelEdit”).findControl(“PosZ”, TextFieldControl.class);
TextFieldControl RX=nifty.getScreen(“ModelEdit”).findControl(“RotX”, TextFieldControl.class);
TextFieldControl RY=nifty.getScreen(“ModelEdit”).findControl(“RotY”, TextFieldControl.class);
TextFieldControl RZ=nifty.getScreen(“ModelEdit”).findControl(“RotZ”, TextFieldControl.class);
TextFieldControl SX=nifty.getScreen(“ModelEdit”).findControl(“SclX”, TextFieldControl.class);
TextFieldControl SY=nifty.getScreen(“ModelEdit”).findControl(“SclY”, TextFieldControl.class);
TextFieldControl SZ=nifty.getScreen(“ModelEdit”).findControl(“SclZ”, TextFieldControl.class);
System.out.println(“Spatial:”+S);
System.out.println(“PX:”+PX);
System.out.println(“PY:”+PY);
System.out.println(“PZ:”+PZ);
System.out.println(“RX:”+RX);
System.out.println(“RY:”+RY);
System.out.println(“RZ:”+RZ);
System.out.println(“SX:”+SX);
System.out.println(“SY:”+SY);
System.out.println(“SZ:”+SZ);
PX.setText(String.valueOf(S.getLocalTranslation().x));
PY.setText(String.valueOf(S.getLocalTranslation().y));
PZ.setText(String.valueOf(S.getLocalTranslation().z));
RX.setText(String.valueOf(S.getLocalRotation().getX()));
RY.setText(String.valueOf(S.getLocalRotation().getY()));
RZ.setText(String.valueOf(S.getLocalRotation().getZ()));
SX.setText(String.valueOf(S.getLocalScale().x));
SY.setText(String.valueOf(S.getLocalScale().y));
SZ.setText(String.valueOf(S.getLocalScale().z));
}[/java]
With warm regards,
Kuro
You can access them with the help of the TextField interface.
[java]
TextField PX=nifty.getScreen("ModelEdit").findControl("PosX", TextField.class);
[/java]
The TextField interface contains all the methods you need.
If you are still getting the NullPointerException, could you post your stacktrace?
I sure can.
I updated it to the Interfacemethod I noticed in a differen thread that you have to use findNiftyControl then. I still get the error though…
It looks like that now:
TextField PX=nifty.getScreen(“ModelEdit”).findNiftyControl(“PosX”, TextField.class);
The important output:
Spatial:boat-ogremesh (Node)
PX:de.lessvoid.nifty.controls.textfield.TextFieldControl@12b3349
PY:de.lessvoid.nifty.controls.textfield.TextFieldControl@1148603
PZ:de.lessvoid.nifty.controls.textfield.TextFieldControl@6a63d3
RX:de.lessvoid.nifty.controls.textfield.TextFieldControl@bfed5a
RY:de.lessvoid.nifty.controls.textfield.TextFieldControl@77eb97
RZ:de.lessvoid.nifty.controls.textfield.TextFieldControl@1b6235b
SX:de.lessvoid.nifty.controls.textfield.TextFieldControl@cb42cf
SY:de.lessvoid.nifty.controls.textfield.TextFieldControl@8f2ca6
SZ:de.lessvoid.nifty.controls.textfield.TextFieldControl@1bc4ec8
07.12.2011 16:21:46 com.jme3.app.Application handleError
SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at de.lessvoid.nifty.controls.textfield.TextFieldControl.setText(TextFieldControl.java:297)
at mygame.controller.GuiController.updateModelEditScreen(GuiController.java:480)
at mygame.controller.GuiController.showModelEditScreen(GuiController.java:118)
at mygame.Main.onAction(Main.java:156)
at com.jme3.input.InputManager.invokeActions(InputManager.java:167)
at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:402)
at com.jme3.input.InputManager.processQueue(InputManager.java:776)
at com.jme3.input.InputManager.update(InputManager.java:826)
at com.jme3.app.Application.update(Application.java:586)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:178)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)
at java.lang.Thread.run(Thread.java:619)
Where line 480 in my class equals
PX.setText(String.valueOf(S.getLocalTranslation().x));
ok, this is the piece of code in the TextFieldControl where it goes wrong:
[java]
@Override
public void setText(final String newText) {
textField.initWithText(nifty.specialValuesReplace(newText));
updateCursor();
}
[/java]
The exact line is the
[java]
textField.initWithText(nifty.specialValuesReplace(newText));
[/java]
line.
From what I can tell, this is because the bind method if the textfield isn’t called yet. This can be caused by the location in your code where you are calling your updateModelEditScreen method.
You can find the complete source for the TextFieldControl class at:
http://nifty-gui.git.sourceforge.net/git/gitweb.cgi?p=nifty-gui/nifty;a=blob;f=nifty-controls/src/main/java/de/lessvoid/nifty/controls/textfield/TextFieldControl.java;h=63778b8b9f9bcaa7ebfaa6cbfa00bce2a93f2fa3;hb=refs/heads/1.3.1
I worked over my code a bit and you were indeed right. I just checked your clue and noticed, that in a special case my UpdateMethod was called before the nifty.gotoScreen() method.
In this case the exception occured. Though the screen was already built it was not binded yet and thats why the error occured. dau
Thanks a lot!
No problem.