I am currently working with a MIDlet (I use Visual MIDlet) in Netbeans, and a NullPointerException is thrown, but I don't know why.
Note. An exception does not occur when a program runs on the emulator only when the OK button is pressed.
Here is the error I get
TRACE: <at java.lang.NullPointerException: 0>, Exception caught in Display class java.lang.NullPointerException: 0 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.soft1(), bci=37 at com.sun.midp.chameleon.layers.SoftButtonLayer.keyInput(), bci=36 at com.sun.midp.chameleon.CWindow.keyInput(), bci=38 at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=17 at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277 at com.sun.midp.events.EventQueue.run(), bci=179 at java.lang.Thread.run(Thread.java:619)
I deleted all the code not related to the exception, so you can read it easier. Below is a simplified version if I have code that throws an exception above.
package stMidlet; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class StoryMidlet extends MIDlet implements CommandListener { private boolean midletPaused = false; private Command commandOk1; private Form form1; private TextField textField1; public StoryMidlet() { commandOk1 = new Command("Ok", Command.OK, 1); textField1 = new TextField("Enter value: ", null, 120, TextField.ANY); form1 = new Form(null, new Item[]{textField1}); form1.addCommand(commandOk1); Display.getDisplay(this).setCurrent(form1); } public void commandAction(Command c, Displayable d) { if (c == commandOk1) { System.out.println("Test"); } }
}
I try to solve this, at least for an hour, without exaggeration. The only thing I can think of is worth mentioning:
- Netbeans displays a warning with the Display.getDisplay (this) ..... line indicating a leak in the constructor. I moved it to the initialize () method, which reassured the warning, but the exception still occurs.
Any help would be greatly appreciated.
Thanks Tom.
java nullpointerexception multithreading java-me lcdui
Tom
source share