I am very new to java and tried to run a simple code of calculating volume. The code is below:
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);
        }
    }
I am able to run the code from eclipse, but when i try to run the code in Command Prompt i get the error:
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.
Please assist.
First class file should be at this location:
C:\Prabhjot\Java\CompleteRefence\build\classes\chapter6\BoxDemo.class
Then you should be inside:
C:\Prabhjot\Java\CompleteRefence\build\classes>
Then issue the command:
java chapter6.BoxDemo

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With