1
votes

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
1
try moving mMainForm initialization from constructor into startApp - per my recollection this way would be more reliable - gnat
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
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
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

1 Answers

1
votes
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();
}