Hi,

I'm trying to run my program in command prompt, but i get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: Invaders

Can anybody tell me what this error means?

Thanx.

Recommended Answers

All 65 Replies

From the documentation


public class NoClassDefFoundError
extends LinkageError

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

Since:
JDK1.0
See Also:
Serialized Form

yassar, thanx! I sorta understand this, but is there a specific line of code i need 2 fix???

No, it's nothing with your code. The class file cannot be found. This is common while using IDE's. The source file is placed in one directory, while the class file somehow ends up in another, and the JVM is looking in the directory that stores the source. Make sure that you have the classfile in the correct directory.

server_crash, thanx! what directories do the classes, .java files, and the sounds and images have 2 be in?

Thank you again.

It's whatever the JVM and JRE are pointing to. If your using an IDE, which I think you are, then the path should be pointing to the directory were the files are located, but in weird circumstances it's not.

What IDE are you using?
Have you looked at the folder that's "suppose" to cotain these files to make sure they are there?

server_crash, I'm using borland jbuilder 9 academic.

well........the error means the JVM can not
find the class file................
there cud b 2 reasons for that...
1. if the class file is not created at all i.e.
being not compiled successfully.
2.the path is not properly set,i.e. JVM
is not finding the class file where it is looking.......

as u said u ar using borland jbuilder.......
dunno bout jbuilder but generally there wud b a directory option
see thru the options and see where
ur directories options are pointing to
and assign the path where ur class files ar created

server_crash, I'm using borland jbuilder 9 academic.

It will be hard for me too help because I don't have JBuilder. Ok, look for an option to change the properties of your project. If you find it, it should say something about the source path,classpath, or the output path. Change it to the directory containing the file your trying to run. That should clear it up.

server_crash, there's an option called "Output Path" you can change. Is this what I'm looking for?

server_crash, there's an option called "Output Path" you can change. Is this what I'm looking for?

That's exactly what your looking for. Now, go find the directory where the source file is, and set the output to that directory.

server_crash, the source files r the .java files - correct?

thanx again for all your help :)

Yes. Actuallly, when you find the folder containing the source file(.java), you should notice the .class file is not in that same folder. If it is, then we have problems! Naturally it should be in the same folder as the source, but since your getting that error, let's hope it's not. If it is in the same folder, then we got some problems with the classpath which will be harder to fix.

Hi,
Make it sure that your in correct path,make sure also that you've compiled
your java source file(s) -(.java).

Hint:at the dos prompt- ex. assuming that your in the directory D:\javafiles just.Type d:\javafiles\d:\j2sdk1.5.0\bin\javac fileName.java.

-email link removed. Please follow up discussions in the forum thread only - Catweazle

Thatz all folks.

actually, when i change the path on jbuilder, it saves the files to the same place. can i copy and paste them to the same folder? another thing's weird: when i type javac, it says it's an unrecognizable command, but when i type java, it works

Ok, you can try to copy and paste the class file into the right directory and try running it. That would probably work, but it wont fix the problem.

You said something about the javac command? Are you using the command line? If so, that error is the result of your environment variables not being set correctly.

server_crash, first, I want to thank you for helping me so much with this problem.

You said something about the javac command? Are you using the command line? If so, that error is the result of your environment variables not being set correctly.

I'm using command prompt. is there a way to change those variables? Also, i created the class files with jbuilder, not console.

Ok, you can try to copy and paste the class file into the right directory and try running it. That would probably work, but it wont fix the problem.

If I copy and paste the files, is there a certain folder name I need. Also, my program has multiple classes. I compile the one with the main method... correct? Last, Should I put all of the sound and picture files in that folder also?

Thank you SO much!

server_crash, first, I want to thank you for helping me so much with this problem.

Your very welcome. I love helping people such as you who are so appreciative and hard working. Keep up the good work!

Ok, since your using the command prompt I can help you even more, because that's what I use. First of all, you need to create a folder on the C drive, and name it whatever you want. This is the folder you'll put all of your source files, class files, and miscelaneous files in.

Now to the environment variables:

Considering you have windows:

Goto start--->right click on my computer--->select properties
Goto the advanced tab, and you should see a button at the bottom that says environment variables...click on that.

The only thing you need to worry about is the PATH variable, and the CLASSPATH variable, nothing else.

SKIP THIS STEP AND GO ON TO THE CLASSPATH, IF IT DOESN'T WORK AFTER SETTING THE CLASSPATH, THEN COME BACK AND SET THIS.
The path variable must point to the bin folder in the sun app server, and the bin folder in the jdk directory. Now, those are two different directories, so you seperate them with a semicolon when creating it. Here is what mine looks like:

C:\Sun\AppServer\bin;C:\Program Files\Java\jdk1.5.0\bin


Classpath....This points to the tools.jar file in the jdk directory. It's pretty easy to find. Here is what mine looks like:

.;%classpath%.;C\Program Files\Java\jdk1.5.0\lib\tools.jar

Your's will look similar, although you do not need the .;%classpath%.; statement.


Next, you need to know how to access your files at the command line.

To do so, you simply type cd/folderName at the command line. The cd stands for current directory. My folder was named javawork, so to access it, I did this at the command prompt:

cd/javawork // brings me to the right directory
javac Hello.java //compiles my program
java Hello //runs my program


Let me know if you don't undestand something or need more help.

first, i need to apoligize for not responding sooner. I've been studying and taking Finals all of last week. They're finally over!!!!!! :)

second, i changed the variables and it worked!

third, the program I'm compiling has 8 .java files. which do i compile first?

server_crash, thank you so much for your help.

Shhewww, that's a lot of work..8 files.

It will be hard to tell what to compile first. You'll need to find the file that calls no other classes. Since I don't know the code or anything, I think the best thing for you, is to compile everyone of them until you don't get an error. You should get an error on the ones that call other classes that aren't compiled. Then once you get one of them compiled, start the process over!

server_crash, thank you so much for your help.

No problem. Your very hard working, and I don't mind helping out such a person. By the way, how did you do on your finals?

I got an A- on my math final but i dunno about the others - I get them back on wednesday

Yes. Actuallly, when you find the folder containing the source file(.java), you should notice the .class file is not in that same folder. If it is, then we have problems! Naturally it should be in the same folder as the source, but since your getting that error, let's hope it's not. If it is in the same folder, then we got some problems with the classpath which will be harder to fix.

I had the same problem as above, and I DO have the .class folder and the .java folder in the same place - in my C: drive. Also, I have the path pointing to the bin folder where the compiler in.

It compiled fine (created the .class folder), and now it won't run.
Please help!

Using an IDE or the Command line?

Using an IDE or the Command line?

Wow - that was a fast reply - using Command line. Is there an easier way?

If you're starting out, I would stick with the command line for a bit. It probably is the classpath, altough you set it. The classpath can be very hard to set, and usually you won't get it the first time.
Please post your current classpath so that I can take a look at what you have.

If you're starting out, I would stick with the command line for a bit. It probably is the classpath, altough you set it. The classpath can be very hard to set, and usually you won't get it the first time.
Please post your current classpath so that I can take a look at what you have.

"C\QTJava.zip"
I think this must be wrong... do you need my regular path too?

I HOPE that's not your classpath!!!! :lol:
It should poin to the tools.jar file in your jdk directory:

Something along the lines of this:
C\Program Files\Java\jdk1.5.0\lib\tools.jar

Take a look at this, this was one of my earlier posts.

Ok, since your using the command prompt I can help you even more, because that's what I use. First of all, you need to create a folder on the C drive, and name it whatever you want. This is the folder you'll put all of your source files, class files, and miscelaneous files in.

Now to the environment variables:

Considering you have windows:

Goto start--->right click on my computer--->select properties
Goto the advanced tab, and you should see a button at the bottom that says environment variables...click on that.

The only thing you need to worry about is the PATH variable, and the CLASSPATH variable, nothing else.

SKIP THIS STEP AND GO ON TO THE CLASSPATH, IF IT DOESN'T WORK AFTER SETTING THE CLASSPATH, THEN COME BACK AND SET THIS.
The path variable must point to the bin folder in the sun app server, and the bin folder in the jdk directory. Now, those are two different directories, so you seperate them with a semicolon when creating it. Here is what mine looks like:

C:\Sun\AppServer\bin;C:\Program Files\Java\jdk1.5.0\bin


Classpath....This points to the tools.jar file in the jdk directory. It's pretty easy to find. Here is what mine looks like:

.;%classpath%.;C\Program Files\Java\jdk1.5.0\lib\tools.jar

Your's will look similar, although you do not need the .;%classpath%.; statement.


Next, you need to know how to access your files at the command line.

To do so, you simply type cd/folderName at the command line. The cd stands for current directory. My folder was named javawork, so to access it, I did this at the command prompt:

cd/javawork // brings me to the right directory
javac Hello.java //compiles my program
java Hello //runs my program


Let me know if you don't undestand something or need more help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.