Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

MIDlet lifecycle

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) {

this.name = name;
}

public void startApp() {

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

public void pauseApp() {}

public void destroyApp(boolean unconditional)
throws MIDletStateChangeException {

this.notifyDestroyed();
}
}

Choices:

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?
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ko Ko
 
author
Posts: 9035
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

Bert
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bert,

Yes, I am using J2ME wireless toolkit from sun.

Thanks for suggestion..
 
reply
    Bookmark Topic Watch Topic
  • New Topic