Chris-Hsu 2008-11-03 11:12
浏览 423
已采纳

请教:java.lang.ClassNotFoundException这是为什么?

请教:java.lang.ClassNotFoundException这是为什么?

以前没有接触过J2ME这一块,对于它现在我是完全陌生的。

首先,我说说我的操作步骤:

1、我下载了eclipsme插件(1.7.9)安装好了,下载了sun_java_wireless_toolkit-2_5_2-windows.exe安装好,本人的机器上安装有eclipse3.4。
2、在window/preference--->J2ME,设置好WTK Root,再设置好Device Management,接着设置好其它几个配置项。

3、编写一个MIDlet。如下:

package cn.chris.test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class TestMIDlet extends MIDlet implements CommandListener {

public TestMIDlet() {
}

private Display display=null;
private Form mainForm =null;
public static final Command exitCommand = new Command("退出",Command.OK,1);

protected  void destroyApp(boolean flag) throws MIDletStateChangeException{
    if(flag){
        display=null;
        mainForm=null;
    }
}

protected  void pauseApp() {

}
//startApp()方法是程序的入口,相当于Java应用程序中的main()方法,startApp()同时是MIDlet的生命周期方法
protected  void startApp() throws MIDletStateChangeException{
    if (display==null)
        display=Display.getDisplay(this);
    mainForm = new Form("Hello");
    String text="Hello World!";
    mainForm.append("\n"+text);
    //为mainForm添加Command,用于与用户交互
    mainForm.addCommand(exitCommand);
    mainForm.setCommandListener(this);
    //将mainForm设置为手机界面当前显示对象
    display.setCurrent(mainForm);
}

public void commandAction(Command cmd, Displayable displayable) {
    if (cmd==exitCommand){
        try {
            destroyApp(false);
        } catch (MIDletStateChangeException e) {
            e.printStackTrace();
        }
        notifyDestroyed();
    }
}

}

RUN,报错:

Running with storage root C:\Documents and Settings\xhb_86\j2mewtk\2.5.2\appdb\DefaultColorPhone
Running with locale: Chinese_People's Republic of China.936
Running in the maximum security domain
java.lang.ClassNotFoundException: cn/chris/test/TestMIDlet
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Scheduler.schedule(+52)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)
Execution completed.
3334814 bytecodes executed
39 thread switches
1667 classes in the system (including system classes)
17248 dynamic objects allocated (514280 bytes)
1 garbage collections (0 bytes collected)

  • 写回答

13条回答 默认 最新

  • soartju 2008-11-06 21:50
    关注

    没有接触过j2me,但是从error log来看,是程序调用
    C:\Documents and ettings\xhb_86\j2mewtk\2.5.2\appdb\DefaultColorPhone下的
    cn/chris/test/TestMIDlet.class文件出错,找不到这个类

    建议先检查下有没有C:\Documents and ettings\xhb_86\j2mewtk\2.5.2\appdb\DefaultColorPhone\cn\chris\test\TestMIDlet.class(肯定没有:))

    没有的话,应该是那个eclipse插件可能需要设置一下编译目录及其它调用参数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(12条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)