所以我在我的J2ME应用程序中添加了一个表单,但在尝试返回主屏幕时总是得到一个nullpointer异常。当我使用画布时,这似乎不会发生,我可以成功返回主菜单。是什么给了什么?
从主midlet启动表单
quickAlarm = new QuickAlarm("Set quick alarm",this);
display.setCurrent(quickAlarm);
QuickAlarm中的构造函数
public QuickAlarm(String title,HelloMIDlet midlet) {
super(title);
df = new DateField("Alarm time",DateField.TIME);
this.append(df);
this.midlet = midlet;
backCommand = new Command("Back",Command.BACK,0);
saveCommand = new Command("Save",Command.OK,1);
this.addCommand(backCommand);
this.addCommand(saveCommand);
}
从QuickAlarm返回主菜单,
this.midlet.leaveCanvas();
这是在主要的midlet
public void leaveCanvas() {
display.setCurrent(startOptions);
}
完整错误是
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:637)
答案 0 :(得分:0)
无视,我只是忘了设置命令监听器。
答案 1 :(得分:0)
定义什么是“quickAlarm”&amp; “startOptions”。你应该能够在“display.setCurrent()”方法中传递“Displayable”对象。所以检查它是否为“quickAlarm”&amp; “startOptions”它们是“javax.microedition.lcdui.Displayable”的子类