Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Please help! java.lang.NoClassDefFoundError problem

1. ## Please help! java.lang.NoClassDefFoundError problem

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.

2. Classpath is likely wrong, you need to ensure that classpath includes the path to the location of HelloPrinter if it is not in the same directory as where your javac is executing.
There are older articles, but nothing has changed since version 1.3 in this regard:
http://download.oracle.com/javase/1....n32/javac.html
http://download.oracle.com/javase/1....classpath.html

Either altering the classpath environment or passing it on the cli will work. I'd pass on the CLI. Also, if you are using an IDE, than it should be keeping track of your classpath relative to how it sees your projects and automatically compile with it set.

3. Originally Posted by Fou-Lu
Classpath is likely wrong, you need to ensure that classpath includes the path to the location of HelloPrinter if it is not in the same directory as where your javac is executing.
There are older articles, but nothing has changed since version 1.3 in this regard:
http://download.oracle.com/javase/1....n32/javac.html
http://download.oracle.com/javase/1....classpath.html

Either altering the classpath environment or passing it on the cli will work. I'd pass on the CLI. Also, if you are using an IDE, than it should be keeping track of your classpath relative to how it sees your projects and automatically compile with it set.
I changed the classpath value to CLASSPATH=C:\bin; where I saved my java, but it still not working.

what should I do? thanks.

4. What is your current cli call for javac?

5. Originally Posted by Fou-Lu
What is your current cli call for javac?
what is cli call???

6. command line interface:
Code:
C:\path\to\jre\bin>javac -cp .;C:\Path\to\otherlibs somejava.java
Pretty much the same in linux if your on a nix system.
I take it you didn't read the articles I posted links for? This sounds more like a problem with your IDE configurations then, and not directly with Java. I've never used JCreator so I can't help you with that.

7. I've also found that this can happen if you create a project with a main class and then try to rename the main class. If it's not done properly you'll get that exact error. I've encountered this in Netbeans, not exactly JCreator...but figured it was worth mentioning.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•