This isn't a syntax error, at least I don't think it is, so much as I don't think my class path is setting properly.
C:\Users\Sparrow\Desktop\My Stuff\Java\Projects\Tuts\Java HTP\2.1 Welcome\Welcom
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome1
Caused by: java.lang.ClassNotFoundException: Welcome1
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: Welcome1. Program will exit.
I get this for anything I try to run using the 'java' command. 'javac' works fine.
I have this 'C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip' set for it. I also tried it with the ' .; ' ahead of it. I'm kind of at a loss here. I'm running vista if that makes a difference.
This is the code:
Netbeans displays the results. Could Netbeans be a part of the issue?
Thank you for your time =)
Edit: I'm looking around on google and from what I'm reading, I have to set this each time I work in a different folder? I thought I simply set in the environment variables and that was that.
this is the common error you would get when you don't set the classpath properly. set the envirnment variables correctly.
set JAVA_HOME to where you install JDK. e.g. JAVA_HOME=C:\Program Files\Java\jdk1.6.0_13
one more thing, add bin folder (e.g. C:\Program Files\Java\jdk1.6.0_13\bin) to the path variable.it allow you to use java related commands irrespective of dirctory path
Now for sure, your example shoud work.
thanks & regards,
It's best to not set the CLASSPATH environment variable at all. If you have it set, then delete the whole variable. Note: You must close and re-open the Windows command prompt after changing the environment variables, otherwise the command prompt won't see the change.
If you don't set the CLASSPATH environment variable, Windows will look in the current directory for class files by default.
Greg Mark wrote:Thank you everyone for the quick replies. I deleted the CLASSPATH from my environment variables and it's working now. =)
Will quick time create this variable again if I run it? I don't use the program, just wondering.
Edit: Also created the JAVA_HOME variable.
There shouldn't be any need to create a JAVA_HOME environment variable unless you are using some tool or library (like ANT maybe for example) which specifically calls for it. The documentation for any such product should mention if it needs this. Otherwise you don't need to set JAVA_HOME as an Environment variable other than for your own convenience or use. I think it is a common misconception that the JAVA_HOME env. variable is somehow required by the java runtime.
Alex Hurtt wrote: There shouldn't be any need to create a JAVA_HOME environment variable unless you are using some tool or library (like ANT maybe for example) which specifically calls for it. The documentation for any such product should mention if it needs this. Otherwise you don't need to set JAVA_HOME as an Environment variable other than for your own convenience or use. I think it is a common misconception that the JAVA_HOME env. variable is somehow required by the java runtime.
I had eclipse setup when I was using Head First before I realized the need for something with better explanations of the whats and whys. I think that had ANT, I switched over to NetBeans b/c that's what the Java site was making use of. Could this possibly mess me up in future endeavors or can I just leave it as is, currently everything seems to be in working order. Then again I am only doing simple programs as per java how to program.