This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError

 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic