请教: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)