我正在尝试执行 Test.class
Test.java 的代码
package pkg;
public class Test {
public static void main(String args[]) {
System.out.println("This is a test");
}
}
我使用它编译了 Test.java,javac -d . Test.java
之后创建了“pkg”目录。然后我做了以下
cd pkg
java Test
此时我收到以下错误消息。
C:\Users\varung\J\pkg>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: pkg
/Test)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
有人可以帮忙吗?