gpt4 book ai didi

java - 线程 "main"java.lang.NoClassDefFoundError 中出现异常。不执行但编译

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:33 25 4
gpt4 key购买 nike

我有简单的程序,

package access;

class Coffee {

void met() {
System.out.println("they accessed me");
}

public static void main(String[] args) {
}
}

我位于路径E:\sarvari\access。它编译正确,我在访问目录中有 .class 文件。我的 CLASSPATH 有 ".;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip;" 我不明白为什么它没有执行。 “ java 咖啡”给我

Exception in thread "main" java.lang.NoClassDefFoundError: access/Coffee
Caused by: java.lang.ClassNotFoundException: access.Coffee"

最佳答案

首先使用编译

   javac -d .  FileName.java 

那么你应该使用

运行程序
 java -cp . access.Coffee // access is your package and coffee is your created class file.
// here . represents the present dir.

关于java - 线程 "main"java.lang.NoClassDefFoundError 中出现异常。不执行但编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24870281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com