File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java.lang.NoClassDefFoundError problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.NoClassDefFoundError problem" Watch "java.lang.NoClassDefFoundError problem" New topic
Author

java.lang.NoClassDefFoundError problem

ray wongray
Greenhorn

Joined: Feb 04, 2011
Posts: 4
hi guy,
I am using JCreator to compile and code java, but when I clicked "run project", it showed that
--------------------Configuration: <Default>--------------------
java.lang.NoClassDefFoundError: HelloPrinter
Caused by: java.lang.ClassNotFoundException: HelloPrinter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: HelloPrinter. Program will exit.
Exception in thread "main"
Process completed.

I google it before and I changed my environment variables to
CLASSPATH .;
JAVA_HOME C:\Program Files\Java\jdk1.6.0_23
PATH .;%SystemRoot%\system32;%JAVA_HOME%\bin;
but it still not working.
Can anyone please help to solve this??
Thanks.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Don't use the CLASSPATH environment variable. It will only cause more problems then it will solve. Just use the -cp argument of java.

The error that you're getting means that the class that you're trying to use can't be found. Is it on the classpath?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And welcome to the javaranch.
ray wongray
Greenhorn

Joined: Feb 04, 2011
Posts: 4
Wouter Oet wrote:Don't use the CLASSPATH environment variable. It will only cause more problems then it will solve. Just use the -cp argument of java.

The error that you're getting means that the class that you're trying to use can't be found. Is it on the classpath?


thanks. I deleted the CLASSPATH variable but it still not working. what should I do??
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
Confirm that the files you want are in the directory you think they are in. Tell us what you found.
Get your command prompt to show you what classpath it is using. Not quite sure what the instruction for that is, however. Something like ECHO %CLASSPATH%, or %CLASSPATH%, but I can't remember the details.
Markas Korotkovas
Greenhorn

Joined: Jan 27, 2011
Posts: 21

You can just type set and hit enter in Command Prompt (in Windows) and it will display all the environment variables used. PATH, CLASSPATH and etc.
ray wongray
Greenhorn

Joined: Feb 04, 2011
Posts: 4
Campbell Ritchie wrote:Confirm that the files you want are in the directory you think they are in. Tell us what you found.
Get your command prompt to show you what classpath it is using. Not quite sure what the instruction for that is, however. Something like ECHO %CLASSPATH%, or %CLASSPATH%, but I can't remember the details.


I saved the java code to C:\bin
and the result of ECHO %CLASSPATH% is
.;C:\bin;C:\Program Files\Java\jdk1.6.0_23\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_23\lib\tools.jar
Markas Korotkovas
Greenhorn

Joined: Jan 27, 2011
Posts: 21

did you remember to compile all your Java classes? Use javac?
ray wongray
Greenhorn

Joined: Feb 04, 2011
Posts: 4
Markas Korotkovas wrote:did you remember to compile all your Java classes? Use javac?


Could you please tell me how to do it??? I use JCreator and I thought it already compiled all the java class when I clicked "run project"
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

It will probably do that for you but you need to be able to walk before you run. What I mean by that you need to be able to do it manually before you resort to an IDE to do it for you. That way you'll understand what is happening and solving problems on a lower level is usually easier.

Assuming that you use Windows: go through this tutorial otherwise pick your OS here.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
Don't like the use of your bin file. Nor the classpath you have set. You might be better off without that classpath at all.
When you open the command line write this
mkdir javawork
cd javawork
Next time you only need the second line. Obviously you can choose any sensible name for your Java™ folder. If you delete your classpath, the compiler will impute a class path of "." = current directory, which is what you want at this stage.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NoClassDefFoundError problem