• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoClassDefFoundError:

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First I am the greenest greenhorn at the JavaRanch.
I'm running a Windows XP box.
I've downloaded J2SDK (1.4.2_01) from Sun, installed, and added to my path c:\j2sdk1.4.2_01\bin.
I'm using the Headfirst Java book as a guide. All my java classes compile (without errors), but when I try to execute them I receive the error: Exception in thread "main" java.lang.NoClassDefFoundError:
I used my limited knowledge to research the issue but I've come up empty.
Any ideas as to what I've done wrong, and what I need to do to correct.

Thanks!
-Chris
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a CLASSPATH issue. Do you have a CLASSPATH environment variable? Does it include the subdirectory where the MyClass.class file is after you compile MyClass.java?
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Chris!
See How To Set the Classpath on our FAQ. This should tell you what you need to know to get yourself up and running.
Of course, if you have any questions about it, feel free to ask them here.
Hope this helps,
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post your code? And how you are trying to run the code.
From one beginner to another, here are some ideas and things that I've seen fix that error.
1)
Make sure when your executing code you don't include .class
so
java program
NOT
java program.class
This seems simple, but I've seen many beginners frustrated because they leave .class on the name.
2) occasionaly this works
java -classpath "." program
3) And the only other thing is maybe your main is not correct. Here's an extremly basic java program.
filename: basic.java

If none of this works then could you post your code?
Goodluck
Eric
 
Chris Kell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help.
The greenhorn is still frustrated.
I read the CLASSPATH FAQ. Did my best to figure what my class path should be. Currently I have it set to: C:\j2sdk1.4.2_01\src\java
I also tried it pointing to my directory where my source is it, but no help.
I tried to execute the compiled code without the .class, same error.
Sample source code is:
public class MyFirstApp {
public static void main (String [] args) {
System.out.println("I Rule");
System.out.println("the World!");
}
}
Thanks for help.
-Chris
 
Chris Kell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok the greenhorn is just stupid!
I re-did my classpath, using my source directory, and magic! It works. I swear I did it before. Maybe I fat-fingered it.
Thanks for the help. I've just taken my first steps in Java.
Thanks
-Chris
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic