Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

andrewk89

Programmer
Mar 28, 2007
9
US
I am currently taking an online Java course at my high school. It's a great course; however, I must use my laptop, because the school computers do not allow me to run my applications after I compile them. When I attempt to run applications, this is the error that I get:

Exception in thread "main" java.lang.NoClassDefFoundError: (name of program)

I have determined that this error is related to a faulty classpath. I echoed the classpath through command prompt and found that the location is:

C:\Program Files\QuickTime\QTSystem\QTJava.zip

I don't know why this is. I set the classpath to the folder that I was running the java application and class file from (my flash drive), but it still didn't work.

What else can I do to get the applications to run? Thanks!
 
By the way, I do have the latest development kits installed.
 
I typed:

set classpath="X:\"

(X is the drive letter for my flashdrive)
 
Well, I have tried all sorts of things:

First, I set my classpath to something like "X:\Online Java", because that was the folder my files were kept in on the flash drive.

That didn't work, so I then set the classpath to the "X:\" drive and moved the files out of the Online Java folder to the drive itself.

After this didn't work, I began wondering if the problem was with the flash drive, so I moved the files to the desktop (so they would be on the hard drive of the computer) in hopes that would help. Still no luck...

 
Well, when setting the classpath, Windows is not case-insensitiv. After I set the classpath to "X:\", I echoed it, and the classpath was changed from the original path of "C:\Program Files\QuickTime\QTSystem\QTJava.zip" to my newly set path of "X:\". So, in that sense, I know the classpath did change.

However, since I'm just learning Java, I'm not really sure how to answer your question about package-definitions. For that reason, it could very well be the problem. Could you elaborate more on what they are and how they must be set?
 
Thanks for the link, it was very informative! The two possibilities seem to be that either:

1) Javac is not in the correct location.
2) My classpath is not correct.



I have tried changing my classpath to the suggested path (CLASSPATH=.;c:\j2sdk140_1\lib) by using the following commands in command prompt:

SET CLASSPATH=".;c:\j2sdk140_1\lib"

I then typed:

echo %classpath%

and the change had been made. However, my applications would still not run correctly. Did I do this the wrong way? If not, is there another way I can set the classpath that may work? As I said earlier, my files are stored in the folder (X:\ONLINE JAVA).

Also, because I am new to the Java language, I'm not really sure what "Javac" is and where it is stored. If this would be causing my problem, what should I do with "Javac"?

Thanks again for the link, Diancecht!
 
If you're using Windows, remember that if you change the classpath variable in a command line window, the change will only apply to commands in that window.

Cheers,
Dian
 
How can I change the classpath correctly then - so that it will remain changed?
 
a) DId you look, whether you have a directory c:\j2sdk140_1\lib at all?
j2sdk140_1 is only an example.

b) and it is a bad one.
I'm almost exclusively running on linux, but AFAIK will java look into it's own libs by default.

c) and that's even not the default libs to look for, but the default would be j2sdk140_1\jre\lib - the Java-Runtime-Environment-libs.

d) Javac is not in the correct location. if javac wasn't in the correct location - how would it compile?
javac is the java-compiler.
And for running your class - you don't need javac, but java.

e) But java gave you that 'No ClassDef found' message.

f) Which Windows-Version?
Using msconfig and setting it in autoexec.bat might be an option for older Windows.


don't visit my homepage:
 
When compiling and executing java apps on school computers, I get used to do the following:

Create a bat file, in the same folder that my classes (actually, in the root folder of all my classes), that contains this:

set CLASSPATH=%CLASSPATH%;.
java myclass

And when executing my app, instead of typing java myclass, I only had to double-click on this bat file, and I was sure that the classpath would be correct.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top