NoClassDefFoundError problem

Y

yihucd

I have a small java program(the smiplest I can have). When I tried to
run after compling it, it shows the error:

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

what might go wrong?

--------------------------------------------------here is what I did
-------------------------
C:\>type test.java
public class test{
public static void main(String[] args){
System.out.println("OK");
}
}

C:\>javac test.java

C:\>dir test.*
Volume in drive C has no label.
Volume Serial Number is B496-E852

Directory of C:\

02/20/2006 02:27 PM 404 test.class
02/20/2006 09:51 AM 93 test.java
2 File(s) 497 bytes
0 Dir(s) 11,949,969,408 bytes free

C:\>java test
Exception in thread "main" java.lang.NoClassDefFoundError: test

C:\>
 
S

send2r

It is a CLASSPATH problem
java is not able to find your class correctly.
since you are on DOS do the following:
before running your calss -
C:\>echo %CLASSPATH%
C:\>set CLASSPATH=C:\;%CLASSPATH%
C:\>java test
Now it should work

note:
step C:\>echo %CLASSPATH% is not necessary. But I asked to do so to
make sure that you have some other folder paths in classpath, that
makes your class invisible.
Also, specifying '.' to represant current dir rather than actual
path(like C:\) would be better
ie;
set CLASSPATH=.;%CLASSPATH% instead of step two.
HTH
RC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top