The question about the completion of the application in j2me, but this does not mean that you exit the application

I have a case in j2me .. I want to end when the application in the process executes the 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 the application, the application is still running or continues to execute and ignores the system.exit function.

still beat 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 occasion?

+2
source share
2 answers

Try calling the norifyDestroyed () method on the MIDlet instance.

0
source

The security exception you get says it all.

J2ME applications do NOT behave like J2SE applications.

You do not start them the same way, and you do not complete them the same way.

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

The MIDlet life cycle is governed by the MIDP runtime, which runs on top of the Java virtual machine, which simply executes Java bytecode and processes system resources.

When MIDlet starts, the MIDP runtime calls the MIDlet constructor and overrides it javax.microedition.midlet.MIDlet.startApp() .

To complete the MIDlet, the MIDP runtime calls an override of javax.microedition.midlet.MIDlet.destroyApp() .

When the MIDlet decides that it can be completed, it can call its own destroyApp() , rather than waiting for the MIDP runtime to execute.

To tell the MIDP javax.microedition.midlet.MIDlet.notifyDestroyed() that it can be safely terminated, the MIDlet MUST call javax.microedition.midlet.MIDlet.notifyDestroyed() , usually as the last method call in destroyApp()

I suggest reading the MIDP specifications to understand all the problems of the life cycle and runtime.

The latest JavaME SDK also contains many well-built midlets for your inspiration.

0
source

Source: https://habr.com/ru/post/1307937/


All Articles