The moose likes Product and Other Certifications and the fly likes MIDlet lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "MIDlet lifecycle" Watch "MIDlet lifecycle" New topic

MIDlet lifecycle

Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Q)What will happen when the following code is executed?

import javax.microedition.midlet.*;

public class MyMIDlet extends MIDlet {

private String name;

public MyMIDlet(String name) { = name;

public void startApp() {

System.out.println("The device name is: " + name);

public void pauseApp() {}

public void destroyApp(boolean unconditional)
throws MIDletStateChangeException {



a) The program will be installed but will throw a RuntimeException when invoked.

b) The program will throw a javax.microedition.MIDletException when invoked.

Which choice is correct one? OR Which exception will be thrown when a MIDlet with non-default constructor is called?
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Actually none of them is correct. java.lang.IllegalAccessException is thrown when the MIDlet is invoked. It's not a RuntimeException type nor a javax.microedition.MIDletException(which does not even exist).

The explanation is that you have to have a no-argument constructor in the class. If you don't want to put one, there should be no other constructor at all. Otherwise, it will throw that IllegalAccessException error, which from the AMS invocation on the class constructor.

Hope it helps...

Co-author of SCMAD Exam Guide, Author of JMADPlus
Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Thanks Ko Ko
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Hi Girish,

Are you using the wireless toolkit from Sun? It's a great way to test your J2ME code questions, and probably the single best way to study for the exam is to write lots of little programs to test stuff out!

Plus, it's free!


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Hi Bert,

Yes, I am using J2ME wireless toolkit from sun.

Thanks for suggestion..
I agree. Here's the link:
subject: MIDlet lifecycle
jQuery in Action, 3rd edition