我对 java 很陌生,并试图运行一个简单的计算量的代码。代码如下:
package chapter6;
class Box {
double width;
double height;
double depth;
}
package chapter6;
public class BoxDemo {
public static void main(String[] args) {
Box myBox = new Box();
double vol;
myBox.depth = 1;
myBox.height = 2;
myBox.width = 3;
vol = myBox.depth * myBox.height * myBox.width ;
System.out.println("Volume: " + vol);
}
}
我可以从 eclipse 运行代码,但是当我尝试在命令提示符中运行代码时,我得到了错误:
C:\Prabhjot\Java\CompleteRefence\build\classes>java BoxDemo.class
Exception in thread "main" java.lang.NoClassDefFoundError: BoxDemo/class
Caused by: java.lang.ClassNotFoundException: BoxDemo.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: BoxDemo.class. Program will exit.
请协助。