MIDlet 中带有左软键的 NullPointerException

发布于 2024-10-20 13:03:00 字数 1505 浏览 1 评论 0 原文

以下运行正常并弹出一个我可以输入的文本字段。手机模拟器的左上角软键可以让我更改输入类型(从 qwerty 到数字等),但是每次按下左上角的按钮时,我都会收到 NullPointerException。任何使用此软键运行的 Midlet 似乎都会发生这种情况(为软键分配具有更高优先级的命令会将输入类型显示推到右上角,在那里它工作正常!)

我有点困惑,有什么问题吗?显然我在这里失踪了(可能)或者是否有我完全失踪的错误/功能?我在 Windows XP 上使用 Netbeans 6.9.1。

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) {
    }
}

编辑:哎呀,忘记了堆栈跟踪:

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江心雾 2024-10-27 13:03:00

当我使用JAVA ME SDK 3.0时,它在我的模拟器中表现相同。

但是当我使用Sun Java WTK 2.5.2 sdk时,甚至没有“更改输入类型按钮”。

我在真实设备 Nokia 5310 Musicexpress 中检查了代码。它似乎工作正常,即我可以更改输入类型、t9 预测、更多输入符号等。

也就是说,更改输入类型按钮取决于实现,并且行为不同。对于 java me sdk 3.0,这可能是一个错误。

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.

冬天的雪花 2024-10-27 13:03:00

我怀疑您发布的任何代码行都会引发 NullPointerException。

我认为唯一的“潜力”是

display.setCurrent(....

(检查 getDisplay 的文档以及它是否可能返回 null),

如果你提供了更多背景信息。

I doubt that any lines of code that you have posted will given rise to the NullPointerException.

The only "potential" as I see it would be

display.setCurrent(....

(check the documentation for getDisplay and whether or not it may return null)

We'd be able to help you further if you provided more context.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文