Search code examples
javajava-menullpointerexceptionmidlet

NullPointerException in MIDlet with left soft key


The following runs ok and pops up a text field that I can type into. The top left soft key on the phone emulator lets me change the input type (from qwerty to numeric etc.) however every time I press this top left button I get a NullPointerException. This seems to happen with any Midlet running with this softkey (assigning a command with a higher priority to the softkey pushes the input type display over to the top right one, where it works fine!)

I'm a bit confused, is there something obvious I'm missing here (likely) or is there a bug / feature somewhere that I'm completely missing? I'm using Netbeans 6.9.1 on Windows XP.

public class Midlet extends MIDlet {

    private Display display;

    public void startApp() {
        display = Display.getDisplay(this);

        display.setCurrent(new Form("") {
            {
                append(new TextField("Label", "", 10, TextField.ANY));
            }
        });
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean destroy) {
    }
}

EDIT: Whoops, forgot stack trace:

TRACE: <at java.lang.NullPointerException:   0>, Exception caught in Display class
java.lang.NullPointerException:   0
        at javax.microedition.lcdui.Display$ChameleonTunnel.callItemListener(), bci=57
        at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=57
        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:662)

Solution

  • It is behaving same in my emulator when I use JAVA ME SDK 3.0.

    But when I use Sun Java WTK 2.5.2 sdk there is even no 'change input type button'.

    I checked the code in real device Nokia 5310 Music express. It seems to work fine i.e I can change input type, t9 prediction on, more input symbols etc.

    That is the change input type button is implementation dependent and behaving differently. In the case of java me sdk 3.0 it may be a bug.