Results 1 to 8 of 8
- 10-10-2012, 01:45 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Error: Could not find or load main class HelloWorld
I have been trying to run this on my computer now. I have a good enough understand of java and just running this simple example to make sure that i can compile and run other programs from the command prompt. It works if i type in the command "java -cp . HelloWorld" but not "java HelloWorld".
I have pasted my prompts, java version and code below.
Please advise me.
W:\Users\phil\College>dir
Volume in drive W is Download
Volume Serial Number is 165A-2356
Directory of W:\Users\phil\College
10/10/2012 11:43 <DIR> .
04/10/2012 15:19 <DIR> ..
09/10/2012 18:20 <DIR> arith
04/10/2012 15:27 <DIR> Eclipse Juno
10/10/2012 12:32 121 HelloWorld.java
09/10/2012 18:36 110 Hello.java
09/10/2012 18:08 <DIR> arith2
10/10/2012 11:43 426 HelloWorld.class
3 File(s) 657 bytes
5 Dir(s) 478,981,750,784 bytes free
W:\Users\phil\College>erase *.class
W:\Users\phil\College>dir
Volume in drive W is Download
Volume Serial Number is 165A-2356
Directory of W:\Users\phil\College
10/10/2012 11:43 <DIR> .
04/10/2012 15:19 <DIR> ..
09/10/2012 18:20 <DIR> arith
04/10/2012 15:27 <DIR> Eclipse Juno
10/10/2012 12:32 121 HelloWorld.java
09/10/2012 18:36 110 Hello.java
09/10/2012 18:08 <DIR> arith2
2 File(s) 231 bytes
5 Dir(s) 478,981,758,976 bytes free
W:\Users\phil\College>javac HelloWorld.java
W:\Users\phil\College>dir
Volume in drive W is Download
Volume Serial Number is 165A-2356
Directory of W:\Users\phil\College
10/10/2012 11:43 <DIR> .
04/10/2012 15:19 <DIR> ..
09/10/2012 18:20 <DIR> arith
04/10/2012 15:27 <DIR> Eclipse Juno
10/10/2012 12:32 121 HelloWorld.java
09/10/2012 18:36 110 Hello.java
09/10/2012 18:08 <DIR> arith2
10/10/2012 12:40 426 HelloWorld.class
3 File(s) 657 bytes
5 Dir(s) 478,981,750,784 bytes free
W:\Users\phil\College>java HelloWorld
Error: Could not find or load main class HelloWorld
C:\Documents and Settings\phil>java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
Java HotSpot(TM) Client VM (build 23.3-b01, mixed mode, sharing)
Java Code:public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } }
- 10-10-2012, 01:56 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Error: Could not find or load main class HelloWorld
You have a CLASSPATH environment variable declared.
Java takes its classpath first from the -cp switch, if that is not provided it then looks for a CLASSPATH variable and uses that.
If that does not exist it defaults to the current directory.
For executable jar files, it only uses the classpath provided in the Manifest in the jar, and ignores any other classpath entirely.Please do not ask for code as refusal often offends.
- 10-10-2012, 02:08 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Error: Could not find or load main class HelloWorld
These are the CLASSPATH and the PATH I have.
Is this right?
W:\Users\phil\College>echo %classpath%
C:\Program Files\Java\jdk1.7.0_07\bin
W:\Users\phil\College>echo %path%
C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C:\WIN
DOWS\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\Microsoft SQL Se
rver\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Progra
m Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Serve
r\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\
Common7\IDE\PrivateAssemblies\;C:\Program Files\QuickTime\QTSystem\;C:\Program F
iles\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Calibre2\;C:\Program
Files\Sage\Sage200\;C:\Program Files\Java\jdk1.7.0_07\bin;C:\PROGRA~1\MICROS~2\O
ffice
- 10-10-2012, 02:18 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Error: Could not find or load main class HelloWorld
Forget about the PATH one.
You want to get rid of the CLASSPATH one.
Utterly useless as it stands, and it's getting in the way.Please do not ask for code as refusal often offends.
- 10-10-2012, 03:01 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Error: Could not find or load main class HelloWorld
how? is it "set CLASSPATH=." or something similar?
and will that fix my problem??
- 10-10-2012, 03:02 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Error: Could not find or load main class HelloWorld
Any suggestions as to why i get the
Error: Could not find or load main class HelloWorld
- 10-10-2012, 03:03 PM #7
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: Error: Could not find or load main class HelloWorld
yes that worked!!
THANKS Tolls
- 10-10-2012, 03:44 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Error: Could not find or load main class HelloWorld
It's set (presumably) in your environment variables in the system itself.
You need to pull up the system control in the control panel.
It'll all be in the windows help.
Search for "environment variables".Please do not ask for code as refusal often offends.
Similar Threads
-
Error:Could Not Find or Load Main Class
By vickyv200 in forum New To JavaReplies: 3Last Post: 08-29-2012, 01:10 AM -
Error: could not find or load main class
By sloppygecko in forum New To JavaReplies: 3Last Post: 08-08-2012, 03:11 PM -
Error: Could not find or load main class HelloWorld
By Cutejeff in forum New To JavaReplies: 12Last Post: 07-19-2012, 07:14 AM -
Error: Could not find or load main class HelloWorld
By grejsimojs in forum New To JavaReplies: 8Last Post: 07-11-2012, 10:27 PM -
Please help! Cannot find or load main class error
By BenH in forum New To JavaReplies: 3Last Post: 12-09-2011, 03:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks