Hello World J2ME应用程序即将在移动设备上发布 - Karbonn K25

时间:2012-04-12 20:30:16

标签: java-me lcdui midp-2.0

我能够将包含jar和jad文件的J2ME应用程序安装到我的手机中。但它一启动就会终止。我无法看到它是否真的打印了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 个答案:

答案 0 :(得分:1)

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

仅对要终止应用程序的命令调用notifyDestroyed(), 如果条件,把它放进去 例如

if(c == Command.BACK){
notifyDestroyed();
}