File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Oh no! NoClassDefFoundError! Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Oh no! NoClassDefFoundError! Help" Watch "Oh no! NoClassDefFoundError! Help" New topic

Oh no! NoClassDefFoundError! Help

Michael Chua

Joined: Apr 21, 2004
Posts: 11
Studying on how to use class imports and came along with a NoClassDefFoundError
I wrote two classes as below, with one using the other

I put the files in a directory called test
when I put the B.class file in the test directory, won't compile
but when I put the B.class file in a subdirectory also called test, A compiles
but when I try to run A, it just shows me the NoClassDefFoundError message
If I take away the package test; line in, it also fails compile

what should I do? change classpath? change directories? change code?
thanks in advance.

Just take my heart when you go<br />I don't have a need for it anymore<br /> <br />5/9 SCJP 1.4 passed<br />8/15 SCBCD 1.3 passed<br />SCWCD (in progress)
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
What happens when you take out the import line in A?
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Take out the "import test.*;" line - you don't need to explicitly import classes that belong to the same package.

Then you need to make sure that package structure matches your directory structure and that the root directory (e.g. in your case, the directory one level above your "test" directory) is included in your classpath. So, if you have C:\projects\test\A.class, make sure C:\projects is included in your classpath.

Finally, when you launch your app, make sure to specify the fully-qualified name, e.g. "java -cp <add your classpath here> test.A"

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
I agree. Here's the link:
subject: Oh no! NoClassDefFoundError! Help
jQuery in Action, 3rd edition