抛出异常处理,当按第二次退出,才真正退出。 package mtk; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class ThrowException extends MIDlet implements CommandListener { private Display display; private Form mainForm; private final static Command CMD_EXIT=new Command("退出",Command.EXIT,1); private boolean isSafeToQuit; public ThrowException() { isSafeToQuit=false; display=Display.getDisplay(this); mainForm=new Form("抛出异常"); mainForm.addCommand(CMD_EXIT); mainForm.setCommandListener(this); } protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { if(unconditional==false){ throw new MIDletStateChangeException(); } } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { display.setCurrent(mainForm); } public void commandAction(Command c, Displayable d) { if(c==CMD_EXIT){ try { if(isSafeToQuit==false){ StringItem msg=new StringItem("忙","重试"); mainForm.append(msg); destroyApp(false); }else{ destroyApp(true); notifyDestroyed(); } } catch (MIDletStateChangeException e) { isSafeToQuit=true; } } } }