java.lang.SecurityException: MIDP lifecycle does not support system exit.

By: Henry  

Usually the Midlets (J2ME programs) doesn't call System.exit(). MIDP applications differ from J2SE applications in the way they terminate. To terminate your MIDlet, you only need to call the MIDlet's notifyDestroyed() method. This signals the AMS that your MIDlet is done executing. The AMS destroys the MIDlet instance and all of its objects. The VM still executes, however.

You want the VM to continue executing so other MIDlets can run. A call to System.exit() signals the VM to terminate. This behavior is undesirable in MIDP applications. Your applications should not terminate the VM; in fact, they can't. If your application calls System.exit(), a java.lang.SecurityException will always be thrown. You'll see a trace back that looks something like the following:

java.lang.SecurityException: MIDP lifecycle does not support system exit.
at java.lang.Runtime.exit(+9)
at java.lang.System.exit(+7)
at HelloWorld3$MyCommandListener.commandAction(+15)
at javax.microedition.lcdui.Display$DisplayAccessor.
at com.sun.kvem.midp.lcdui.EmulEventHandler$

There are two main reasons why a MIDlet should not shut down the VM. First, other applications may be running; terminating the VM would destroy them. Second, you never start up the VM; therefore, you should not shut it down. The AMS controls the VM. It starts it and terminates it when it detects it's not needed, or if it needs to manage system resources.

Archived Comments

Most Viewed Articles (in J2ME )

Latest Articles (in J2ME)

Comment on this tutorial