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.
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 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: 32712
4
posted
0
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.
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
posted
0
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
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: 32712
4
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.