tags:

views:

249

answers:

2

i have case in j2me .. i want terminate when app in process execute code. this is my simple code.

else if (c == cmdStop) {

          //command berhenti
             browser.stop();

         }


 public void stop(){
          // No errors
                  int errorCode = 0;

                 // An error occurred
                    errorCode = -1;

                  // Terminate
                       System.exit(errorCode);

         }

the problem is when i try to terminate app, the app still worked or continue execute and ignore function system.exit.

still excecute this code

private void paintParserScreen(Graphics g){

     int w = width;
     int h = fontHeight+2;
     int x = 0;
     int y = height - h;

     int curLoaded = 0;
     int value = 0;
     int iPercent = 0;



     if(maxElementNum!=0){
      curLoaded = wapRender.getCurLoadedTag();
      value = curLoaded * 100 / maxElementNum;
            iPercent = (curLoaded * (w - 2)) / maxElementNum;
     }

     g.setColor(0x808080);
        g.fillRect(x, y, w, h);

        g.setColor(0x0000ff);
        g.fillRect(x + 1, y + 1, iPercent - 2, h - 1);

        g.setColor(0xffffff);
        g.drawString("proses..." + value+"%", 
             width>>1, y + 1, Graphics.TOP|Graphics.HCENTER);
    }

and they said

java.lang.SecurityException: MIDP lifecycle does not support system exit.
    at java.lang.Runtime.exit(+9)
    at java.lang.System.exit(+7)
    at com.gameislive.browser.Browser.stop(+8)
    at Tampilkan.commandAction(+147)
    at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
    at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
    at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
    at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)

please help me what should i do for this case?

A: 

Try calling norifyDestroyed() method in MIDlet instance.

JaanusSiim
i think it used for quit from application .. i had tried this method
Kuya
Your question + comment... It does not compute...
JaanusSiim
A: 

The security exception you get says it all.

J2ME applications do NOT behave like J2SE applications.

You don't start them in the same way and you don't terminate them in the same way.

In your case, the kind of J2ME application you are trying to write is called a MIDlet.

A MIDlet lifecycle is regulated by the MIDP runtime that runs on top of a Java Virtual Machine that simply executes Java bytecode and handles system resources.

When a MIDlet starts, the MIDP runtime calls the MIDlet constructor and its javax.microedition.midlet.MIDlet.startApp() override.

In order to terminate a MIDlet, the MIDP runtime calls the javax.microedition.midlet.MIDlet.destroyApp() override.

When the MIDlet decides that it can be terminated, it can call its own destroyApp() instead of waiting for the MIDP runtime to do it.

In order to tell the MIDP runtime that it can be safely terminated, a MIDlet MUST call javax.microedition.midlet.MIDlet.notifyDestroyed(), typically as the last method call in destroyApp()

I suggest reading the MIDP specifications in order to understand all the lifecycle and runtime issues.

The latest JavaME SDK also contains many properly constructed MIDlets for your inspiration.

QuickRecipesOnSymbianOS