因此,我正在向我的J2ME應用程序添加一個表單,但在嘗試返回主屏幕時總是得到空指針異常。當我使用畫布時,這似乎不會發生,我可以成功回到主菜單。是什麼賦予了?在J2ME中切換顯示器時得到空指針異常
從主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)
display.setCurrent(startOptions); * startOptions *設置在哪裏? – frayser 2010-11-23 15:05:39