J2ME的 Hello World的问题
我写的HelloWorld程序为什么总是运行不出来:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Example extends MIDlet implements CommandListener{
private Display dis;
private TextBox tb;
private Command exitCom;
public Example(){
dis = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
String str = "Hello World! ";
tb = new TextBox( "Hello ",str,str.length(),0);
exitCom = new Command( "Exit ",Command.EXIT,1);
tb.addCommand(exitCom);
tb.setCommandListener(this);
dis.setCurrent(tb);
}
public void commandAction(Command e, Displayable d) {
if(e ==exitCom){
try {
this.destroyApp(false);
} catch (MIDletStateChangeException e1) {
System.out.println( "error ");
}
notifyDestroyed();
}
}
}
------解决方案--------------------把初始化的语句都放在构造里, startApp() 只用setCurrent()
------解决方案--------------------你一直有问题主要有两个可能:
1. 你将你的Eclipse安装在了中文目录下;
2. 将你源代码中的 "if(e ==exitCom) "改成 "if(e.getLabel().equals( "Exit ")) "
------解决方案--------------------代码本身没有任何的问题可能导致这种情况发生。。。。。检查一下你的wtk和运行环境。