So, I am working on a project that uses inheritance. I have a class Creature, which extends Thing. Also, I have classes Tiger and Ant that extend creature. I also have a TestCreature class. All of these are in the same directory, and they all compile.
However, when I run them all, I get an exception stating:
Exception in thread "main" java.lang.NoClassDefFoundError: Creature/java
Caused by: java.lang.ClassNotFoundException: Creature.java
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... Can anybody help me fix this? I honestly am not even sure what all that means...

8 Years
Discussion Span
Last Post by Ezzaral

You have to set the classpath correctly to execute your program. in the command prompt or in the editor that you use, please set the classpath. In command prompt you can set the classpath like this:

set classpath=%classpath%;.;D:\java\programs;

where D: is the drive in which the programs are stored and programs is your current directory. Hope you have knowledge in directory structure. If you have any doubt please feel free to ask


He stated that they are all in the same directory. It's not a classpath issue. His error message is exactly what you get when you try to execute the ".java" file instead of the class. The "." is interpreted as a package separator, hence the "Creature/java" result.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.