• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

NoClassDefFoundError

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80057
409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic