专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > J2ME

J2ME的 Hello World的有关问题

发布时间:2010-06-05 12:38:20 文章来源:www.iduyao.cn 采编人员:星星草
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和运行环境。
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: