Java.lang.NoClassDefFoundError 在命令提示符下 运行

Java.lang.NoClassDefFoundError in command prompt run

我正在尝试 运行 我在命令提示符下的代码,它给我错误.. 谁能知道它出了什么问题?

错误:找不到或无法加载主class你好 Caused by: java.lang.NoClassDefFoundError: FirstQuarter/hello (错误的名字: 你好)

此类错误是由于 class 在运行时未在 Classpath 中找到,但在编译时找到。 查找打印

System.getproperty("java.classpath")

这将打印 class 路径,以便您了解实际运行时 class 路径。

此外,请确保将 class 的完全限定名称传递给“java”命令,其中包含要执行的主要方法。

directory_that_holds_package>java package_name.Class_name

首先,我猜测你的程序在Eclipse和Idea中可以运行顺利,但是在命令行中却报这个错误。

现在,您应该在命令行中包含程序的 package。如果你的程序是这样的:

package firstprogram;

public class HelloWorld { 
  public static void main(String args[]) { 
    System.out.println("Hello World"); 
  } 
}

那么你应该 运行 java firstprogram.HelloWorld 在 FirstQuarter 文件夹中。

此错误主要是由于程序无法访问您在程序中定义的 class,这可能是由于您没有定义正确的 class ]path 或者您没有包含 运行 class 所需的库。原因可能有很多。

因此请尝试 运行 任何 IDE 上的代码,因为您将能够轻松识别错误。