java.lang.ClassNotFoundException

用WTK文件编译下面程序事出错

package j2meform;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class newForm extends MIDlet implements Runnable,CommandListener{
int i=0;
static newForm instance;
Display display=null;
Form f=new Form("FORM实验");
TextField tfuser=new TextField("用户名:","",10,TextField.ANY);
TextField tfpasswd=new TextField("密码:","",16,TextField.NUMERIC|TextField.PASSWORD);
Command okCommand=new Command("确定",Command.OK,1);
Gauge gauge=new Gauge("正在验证",false,5,0);
public newForm() {
instance = this;
}

public void startApp() {
if(display==null){
display=Display.getDisplay(this);
f.append(tfuser);
f.append(tfpasswd);
f.addCommand(okCommand);
f.setCommandListener(this);
}
display.setCurrent(f);
}

public void pauseApp() {
Alert alertpause=new Alert("pause","暂停ING...",null,AlertType.WARNING);
}

public void destroyApp(boolean unconditional) {
}

public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}

public void run() {
int jindu=0;
while(jindu<6){
gauge.setValue(jindu++);
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException ex) {
System.out.println("多线成出错");
ex.printStackTrace();
}
}
TextBox tb=new TextBox("已登陆","FORM实验成功",100,TextField.ANY);
display.setCurrent(tb);
}

public void commandAction(Command command, Displayable displayable) {
String struser=tfuser.getString();
String strpasswd=tfpasswd.getString();
if(struser.equals("shuchuanyu")&&strpasswd.equals("888555")){
//验证正确;
f.append(gauge);
Thread t=new Thread(this);
t.start();
}else{
//验证错误;
i++;
Alert alert=new Alert("ERROR","未通过验证!",null,AlertType.WARNING);
display.setCurrent(alert,display.getCurrent());
if(i==5)
quitApp();
}
}

}

错误:
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\DefaultColorPhone
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
Unable to create MIDlet newForm
java.lang.ClassNotFoundException: newForm
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Selector.run(+22)

麻烦大家看下,谢谢~
这个问题解决了,是路径名和包名不一致的问题。可现在JAR程序在WTK里能运行,但在手机里运行就提示应用程序错误,麻烦大家在看下,谢谢了...

1.wtk新建工程
2.输入midlet名称,这一步注意,要把包路径一起输进去。比如,如果你继承自midlet的类newForm是存在于j2meform包下,那么midlet的名称就是j2meform.newForm,而不能仅仅写newForm。
3.把你写的源文件复制到新建的工程目录下的src目录下,用到的资源文件复制到res目录。
4.编译,运行
补充:手机里如果有错误,则可能是你选用的MIDP或者CLDC版本过高。在设置时都选为1.0试试
温馨提示:答案为网友推荐,仅供参考
第1个回答  2023-05-14
java.lang.ClassNotFoundException is a type of exception that is thrown when a Java program tries to load a class at runtime, but the class cannot be found in the classpath. This usually happens when the classpath is not set correctly or when the class is not included in the classpath.There are several reasons why this error can occur, including:1. The classpath is not set correctly2. The class was not compiled or packaged correctly3. The class is not in the correct location in the classpath4. The class has been removed from the classpath or is no longer available5. The class is part of a third-party library that is not included in the classpath.To resolve this error, you will need to check the classpath and ensure that the class that is causing the error is included. You may also need to recompile or package the class if it was not done correctly, or reinstall any third-party libraries that are required.
第2个回答  2008-06-11
是不是用MIDLet的文件包没有被reference到
第3个回答  2008-06-11
是不是缺少某个包文件哇?
相似回答