Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NoClassDefFoundError

 
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.
 
Marshal
Posts: 69864
278
  • 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?
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic