wood burning stoves
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFoundError:" Watch "NoClassDefFoundError:" New topic


Chris Kell

Joined: Oct 04, 2003
Posts: 3
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.

Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
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?

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

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,

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Eric Hoskland

Joined: Oct 12, 2000
Posts: 29
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.
Make sure when your executing code you don't include .class
java program
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?
Chris Kell

Joined: Oct 04, 2003
Posts: 3
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 Kell

Joined: Oct 04, 2003
Posts: 3
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: NoClassDefFoundError:
It's not a secret anymore!