冷面閻羅

          低調做人&&高調做事
          隨筆 - 208, 文章 - 3, 評論 - 593, 引用 - 0
          數據加載中……

          J2ME程序的奇怪現象

                我周日寫的程序,當時運行是沒有問題的。今天運行奇了怪出問題。我看了代碼沒有問題就是出異常。代碼如下
          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.midlet.MIDlet;
          import javax.microedition.midlet.MIDletStateChangeException;


          public class TestExit extends MIDlet implements CommandListener {
              
          private Display display;
              
          private Form form;
              
          private final static Command cmd_exit=new Command("EXit",Command.EXIT,1);

              
          public TestExit() {
                  display
          =Display.getDisplay(this);
                  form
          =new Form("Exit");
              }


              
          protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

              }


              
          protected void pauseApp() {

              }


              
          protected void startApp() throws MIDletStateChangeException {
                  form.addCommand(cmd_exit);
                  form.setCommandListener(
          this);        
                  display.setCurrent(form);

              }


              
          public void commandAction(Command c, Displayable d) {
                  
          if(c==cmd_exit){
                      System.out.println(
          "in");
                      
          try {
                          destroyApp(
          false);
                          notifyAll();
                      }
           catch (MIDletStateChangeException e) {
                          e.printStackTrace();
                      }

                  }

              }


          }

          出的錯誤如下:
          java.lang.IllegalMonitorStateException
              at TestExit.commandAction(
          +24)
              at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(
          +280)
              at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(
          +10)
              at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(
          +68)
              at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(
          +258)

          posted on 2007-06-28 19:01 冷面閻羅 閱讀(401) 評論(1)  編輯  收藏 所屬分類: j2me

          評論

          # re: J2ME程序的奇怪現象  回復  更多評論   

          問題找到是退出時選擇函數有問題:
          destroyed(false) MIDlet在接到通知后拋出MIDletStateChangeException而保持在當前狀態,
          destroyApp(false)代表程序是由硬件或非系統關閉掉的
          notifyDestroyed通知應用程序管理器,該midlet已進入銷毀狀態,隨時可以回收內存
          2007-06-28 19:19 | 冷面閻羅

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 黄浦区| 昭苏县| 舟曲县| 黄石市| 松滋市| 维西| 中牟县| 伊宁县| 甘南县| 黄石市| 株洲市| 辽中县| 新泰市| 双峰县| 伊宁市| 乌什县| 陇川县| 惠州市| 海阳市| 庐江县| 城步| 尉犁县| 开平市| 胶南市| 靖州| 屏山县| 松原市| 日土县| 锦州市| 营山县| 文水县| 犍为县| 武乡县| 东安县| 南投市| 明星| 长治县| 盱眙县| 建始县| 内乡县| 蒲城县|