我有简单的 Hello word 程序。当不在代码中声明命名空间时,程序将编译并运行,但是当我在命名空间中声明类并编译程序时,它将成功编译,但在该程序运行时会给出错误 classnotfound。我的问题是为什么 java 编译器在代码中声明命名空间(包)时无法找到类?
请在下面找到源代码:
package org;
public class Chunk
{
public static void main(String [] args)
{
System.out.println("Hello, World");
}
}
命令是
java org.Chunk
错误是
java.lang.NoClassDefFoundError: org/Chunk
Caused by: java.lang.ClassNotFoundException: org.Chunk
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.Chunk. Program will exit.
Exception in thread "main"