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...
Thanks!!

Recommended Answers

All 3 Replies

Don't try to execute "Creature.java" - execute "Creature" after you have compiled to a class file.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.