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.
source share