错误:java/lang/NoClassDefFoundError:java/lang/Object
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22063390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: java/lang/NoClassDefFoundError: java/lang/Object
提问by Death Metal
I am using Linux Ubuntu 13.10 I am trying to run a script and get the following error:
我正在使用 Linux Ubuntu 13.10 我正在尝试运行脚本并收到以下错误:
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar: Success
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar: Success
Error occurred during initialization of VM
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
java/lang/NoClassDefFoundError: java/lang/Object
I have:
我有:
javac -version
javac -version
javac 1.7.0_51
javac 1.7.0_51
java -version
版本
java version "1.7.0_51"
java version "1.7.0_51"
OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.13.10.1)
OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.13.10.1)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
When I run:
echo $CLASSPATH
: I get blank output
当我运行时::
echo $CLASSPATH
我得到空白输出
echo $JAVA_HOME
: blank output
echo $JAVA_HOME
: 空白输出
Please help me, how to resolve this.
请帮助我,如何解决这个问题。
回答by Andres
You have to set your CLASSPATH and JAVA_HOME environment variables. Take a look at this:
您必须设置 CLASSPATH 和 JAVA_HOME 环境变量。看看这个:
https://askubuntu.com/questions/186693/how-set-classpath-variable-for-a-folder-in-ubuntuhttp://www.wikihow.com/Set-Up-Your-Java_Home-Path-in-Ubuntu
https://askubuntu.com/questions/186693/how-set-classpath-variable-for-a-folder-in-ubuntu http://www.wikihow.com/Set-Up-Your-Java_Home-Path-in -Ubuntu
This could be useful as example, replacing the directories by yours:
这可能很有用,例如,用您的目录替换目录:
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"
export CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib"
导出 JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"
export CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib"
回答by Maulik Patel
After you compile your code, you end up with .class files for each class in your program. These binary files are the bytecode that Java interprets to execute your program. The NoClassDefFoundError indicates that the classloader, which is responsible for dynamically loading classes, cannot find the .class file for the class that you're trying to use. It probably indicates that you haven't set the classpath option when executing your code. This link explains how to set the classpath when you execute
编译代码后,您最终会得到程序中每个类的 .class 文件。这些二进制文件是 Java 为执行程序而解释的字节码。NoClassDefFoundError 表示负责动态加载类的类加载器找不到您尝试使用的类的 .class 文件。这可能表明您在执行代码时没有设置类路径选项。此链接解释了如何在执行时设置类路径