编程论坛's Archiver

masefee519 发表于 2007-12-20 21:48

J2ME问题

请问我编译的一个程序,用模拟器运行时,一运行那模拟手机一闪而过,程序并没有问题啊??怎么回事呢,谢谢各位!

package Demo;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MMS extends MIDlet {
         private TextBox textbox; // TextBox 显示一条消息
         private Display disp; // 引用MIDlet的Display 对象
         private Command cmdExit; // 设定按钮用于退出MIDlet
         private Command cmdOK; // 确定按钮
         private Alert alt; // 信息提示对象

        public MMS() {
                super();
                disp = Display.getDisplay(this); // 获得当前MIDlet的Display对象
                cmdExit = new Command("退出", Command.SCREEN, 1); // 新建两个控制按钮
                cmdOK = new Command("阅读", Command.OK, 1);
                textbox = new TextBox("请输入待阅项目序号:", "", 40, 0); // 新建文本框
                textbox.addCommand(cmdExit); // 添加控制按钮
                textbox.addCommand(cmdOK);
                textbox.setCommandListener((CommandListener) this); // 开始侦听命令
        }

        protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
                // TODO Auto-generated method stub

        }

        protected void pauseApp() {
                // TODO Auto-generated method stub

        }

        protected void startApp() throws MIDletStateChangeException {
                alt = new Alert("整蛊专家 V1.0");// 开始运行时显示版权信息,新建信息框对象
                // 设置显示字符串
                alt.setString("==== 整蛊专家 V1.0 ====尹晓飞2007年作版权所有(C) 2007-2007");
                alt.setType(AlertType.INFO); // 设置为普通阅读信息框
                alt.setTimeout(Alert.FOREVER); // 信息窗口在按下DONE键后才能进入下一页面
                disp.setCurrent(alt, textbox); // 显示信息窗口

        }
       
        public void commandAction(Command arg0, Displayable arg1) throws MIDletStateChangeException {
        if (arg0 == cmdExit) { // 按下退出键时停止运行
           destroyApp(false);
           notifyDestroyed();
        }
        if (arg0 == cmdOK) { // 按下阅读键后阅读对应信息
            TextBox textbox = (TextBox)arg1; // 得到用户输入的内容
            String sInfo = textbox.getString();
    if (sInfo.equals("1") || sInfo.equals("2") || sInfo.equals("3") || sInfo.equals("4") || sInfo.equals("5")) { // 显示项目1的内容
        // 根据所选项目选择要显示的内容
        if (sInfo.equals("1")) alt.setString("一兄");
        if (sInfo.equals("2")) alt.setString("猪");
        if (sInfo.equals("3")) alt.setString("春…");
        if (sInfo.equals("4")) alt.setString("为什");
        if (sInfo.equals("5")) alt.setString("昨");
            alt.setTitle("您正在阅读短信" + sInfo); // 设置标题
        }
    else{
            alt.setString("很抱歉,暂时还没有您选择的项目,请重新输入!");
            alt.setTitle("错误警告"); // 设置标题
        }
            alt.setType(AlertType.INFO); // 设置为普通阅读信息框
            alt.setTimeout(Alert.FOREVER); // 信息窗口在按下DONE键后进入下一页面
            Display.getDisplay(this).setCurrent(alt, textbox); // 显示信息窗口
        }
        }
}

marer 发表于 2008-1-25 11:33

检查你的模拟器是用的什么JDK安装的,有时候你的程序开发时用的JDK版本和模拟器的JDK版不一致,会导致这个问题的发生。例如:我的电脑上有两个版本的JDK,一个1.4.2,一个1.5.0_11,在Eclipse中开发时Eclipse默认是使用JDK1.5,但程序使用的JDK是1.4,这样就会出现楼主说的问题,只要把两个JDK版调一致就可以了

千里冰封 发表于 2008-1-25 13:10

还有,不要出现中文路径名

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.