NullPointerException On a Calling a Function
I'm building a program that gets the value of a TextField
, concatenate with some other Strings
and then display them on a TextBox
when the ScreenCommand
is clicked, the problem is that it's calling a NullPointerException
. My code is like this(of course it has a lot more stuff):
/* .... */
} else if (command == submitCommand) {
FirstPart();
// write pre-action user code here
switchDisplayable(null, getTextBox3());
// write post-action user code here
}
/* .... */
public void FirstPart() {
String test = null;
test = "tst" + textField.getString() + "test";
textBox3.setString(test);
}
/* .... */
And I get this when I click the开发者_如何学C menu:
TRACE: <at java.lang.NullPointerException: 0>, Exception caught in Display class
java.lang.NullPointerException: 0
at mp.releaser.MPReleaser.FirstPart(MPReleaser.java:535)
at mp.releaser.MPReleaser.commandAction(MPReleaser.java:128)
at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
at com.sun.midp.chameleon.layers.SoftButtonLayer.commandSelected(), bci=11
at com.sun.midp.chameleon.layers.MenuLayer.pointerInput(), bci=188
at com.sun.midp.chameleon.CWindow.pointerInput(), bci=88
at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handlePointerEvent(), bci=19
at com.sun.midp.lcdui.DisplayEventListener.process(), bci=296
at com.sun.midp.events.EventQueue.run(), bci=179
at java.lang.Thread.run(Thread.java:680)
What should I do to correct this?
PS: Netbeans should have a NullPointerException
corrector tool :P
Looking at the FirstPart
method, the only thing I can imagine is that textField
is null
or textBox3
is null
. Are you sure it isn't null
?
If I'm completely missing the point of your question, I apologize.
EDIT: Thank you, StriplingWarrior!
The only place a NullPointer
can occur here is textField.getString()
method or textBox3
. Debug there.
精彩评论