1

I was able to install a J2ME app consisting of a jar and jad file into my mobile. But it terminates as soon as it is launched. I am not able to see if it actually prints Hello World.

HelloWorld.java


    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;

    public class HelloWorld
        extends MIDlet 
        implements CommandListener {
      private Form mMainForm;

      public HelloWorld() {
        mMainForm = new Form("HelloWorld");
        mMainForm.append(new StringItem(null, "Hello, MIDP!"));
        mMainForm.addCommand(new Command("Exit", Command.EXIT, 0));
        mMainForm.setCommandListener(this);
      }

      public void startApp() {
        Display.getDisplay(this).setCurrent(mMainForm);
      }

      public void pauseApp() {}

      public void destroyApp(boolean unconditional) {}

      public void commandAction(Command c, Displayable s) {
        notifyDestroyed();
      }
    }

Manifest.mf

Manifest-Version: 1.0
MIDlet-Name: HelloWorld
MIDlet-1: HelloWorld, , HelloWorld
MIDlet-Vendor: Ankit Gupta
MIDlet-Version: 1.0.0
MIDlet-Description: HW
MIDlet-Info-URL: http://google.com
MicroEdition-Profile: MIDP-2.0
MicroEdition-Configuration: CLDC-1.0

HelloWorld.jad
----------------------------
MIDlet-1: HelloWorld, , HelloWorld
MIDlet-Name: HelloWorld
MIDlet-Version: 1.0.0
MIDlet-Vendor: Ankit Gupta
MIDlet-Jar-URL: HelloWorld.jar
MIDlet-Jar-Size: 1212
MicroEdition-Profile: MIDP-2.0
MicroEdition-Configuration: CLDC-1.0
gnat
  • 6,213
  • 108
  • 53
  • 73
Ankit Gupta
  • 23
  • 1
  • 3
  • try moving `mMainForm` initialization from constructor into startApp - per my recollection this way would be more reliable – gnat Apr 13 '12 at 08:44
  • I am using oracle_java_me_sdk-3_0_5 for compiling my class. Definitely there is problem with my compilation technique. need help on this. – Ankit Gupta Apr 13 '12 at 12:43
  • 1
    your code snippet looks OK to me, i wouldn't expect it fail compilation. Even the code that I suggested to move, is OK compile-wise. Regarding Java ME SDK, does your midlet run OK on it? per my reading of your question, the problem appears only on real mobile – gnat Apr 13 '12 at 12:49
  • I agree with @gnat your code really seems OK.Maybe it does not have nothing to do with it, but have you tried to set the StringItem label instead of passing null? Maybe this is a limitation of your mobile VM. – Telmo Pimentel Mota Apr 13 '12 at 20:09

1 Answers1

1
public void commandAction(Command c, Displayable s) {
notifyDestroyed();
}

Call notifyDestroyed() only for commands for which you want to terminate application, Put it in if condition e.g.

if(c == Command.BACK){
notifyDestroyed();
}
nikhilr57
  • 115
  • 7