*
The moose likes Beginning Java and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic
Author

NoClassDefFoundError

thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Hi Everyone,

I work with java 1.4, but I wrote a very small program with enums and that could not be compiled with 1.4 so I compiled with 1.6. Then I tried run the class using java classname

But I got the following message :
Exception in thread "main" java.lang.NoClassDefFoundError: aa

I know this is some problem due to class path setting as both versions are installed on my system. I tried to fix this with java -classpath.aa , but this gives the following error:

Unrecognized option: -classpath.aa
Could not create the Java virtual machine.

Please tell me how I can fix this so that I can test new java features with little code snippets.

Thanks,
Thejaswini.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Are you really calling your classes things like "aa"? If you compiled it with Java6 make sure to run it with Java6. The classpath has nothing to do with finding the java executable file; you need to alter your PATH to change between Java6 and J2SE1.4. The -classpath option is designed for including distant files (usually .jar files) and probably won't help you here. You can alter the path temporarily, provided you can remember where you installed J2SE1.4 and Java6; you can find out how to do it on this old thread (Windows), or this old thread (Linux).

Do you have a package declaration in your class? That might make your .class files more difficult to find. If you have package declarations, then tell us.

I presume (from what you say) that the file was compiled successfully.

Try the dir (Windows) or ls (Linux) instruction to find out whether the aa.class file is in your present folder. The usual cause of a NoClassDefFoundError is that your command prompt or terminal window is not "pointing at" the correct location of the file. You will have to use the cd instruction to navigate to the correct folder. That is obviously where you saved the .java file and (if there isn't a package declaration) where the class file will be.
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Thanks for the reply!

Yes the file is compiled(apparently) since I dont get any errors. But there is no class file in that location(or anywhere else)

Could you please point me in the right direction?
 
 
subject: NoClassDefFoundError
 
Similar Threads
Unable to initialize Struts ActionServlet due to an unexpected exception
strictfp and abstract
Installation Problem
Applet not working on old computers
error message