Results 1 to 9 of 9
- 05-15-2012, 05:54 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Compiles fine but error when try to run
Hi All,
Does someone have any idea why the following code works in Eclipse with no problems but on
command line()does not run.
it compiles fine and creates a class files as well, but gives the error:Java Code:public class Hello{ public static void main(String args[]){ System.out.println("Hi"); } }
could not find or load main class Hello
when i try to run this with:
java Hello
Thank You in advance!
Tariq
- 05-15-2012, 05:58 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Compiles fine but error when try to run
Where are you running this from?
That is, what directoy, and does that directory contain the Hello.class file?
Do you have a CLASSPATH environment variable set, if so then either remove it or use '-cp.' in your java command.Please do not ask for code as refusal often offends.
- 05-15-2012, 06:41 PM #3
Re: Compiles fine but error when try to run
when you open the command prompt window enter: dir
to show the folders contents before entering the java command.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.If you don't understand my response, don't ignore it, ask a question.
- 05-15-2012, 08:53 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: Compiles fine but error when try to run
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Tariq>cd Desktop
C:\Users\Tariq\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is 9EAA-975F
Directory of C:\Users\Tariq\Desktop
14/05/2012 23:44 <DIR> .
14/05/2012 23:44 <DIR> ..
30/04/2012 23:42 1,126 Aptana Studio 3.lnk
12/02/2012 18:21 870 Downloads - Shortcut.lnk
19/04/2012 22:58 1,227 eclipse - Shortcut (2).lnk
25/02/2012 13:02 949 eclipse - Shortcut.lnk
12/05/2012 09:09 42 first.js
30/04/2012 23:16 2,397 Google Chrome.lnk
15/05/2012 16:50 406 Hello.class
14/05/2012 23:44 100 Hello.java
11/03/2012 19:26 1,282 Launch WhiteSmoke - Shortcut.lnk
10/03/2012 11:05 2,394 MySQL 5.5 Command Line Client.lnk
13/05/2012 13:39 <DIR> nodeWork
21/04/2012 12:41 732 Photos Family - Shortcut.lnk
12/05/2012 03:58 <DIR> Removed From Desktop Just after Second Semes
ter
14/05/2012 23:22 518 Test1.class
14/05/2012 23:22 275 Test1.java
12/05/2012 10:10 <DIR> wep tec week 12
17/11/2011 19:47 696 Workspace - Shortcut.lnk
14 File(s) 13,014 bytes
5 Dir(s) 73,063,886,848 bytes free
C:\Users\Tariq\Desktop>
- 05-15-2012, 08:57 PM #5
Re: Compiles fine but error when try to run
Where did you enter the java command and get the error message?
If you don't understand my response, don't ignore it, ask a question.
- 05-15-2012, 09:41 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: Compiles fine but error when try to run
Oh sorry here it is now at the very end:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Tariq>cd Desktop
C:\Users\Tariq\Desktop>dir
Volume in drive C has no label.
Volume Serial Number is 9EAA-975F
Directory of C:\Users\Tariq\Desktop
14/05/2012 23:44 <DIR> .
14/05/2012 23:44 <DIR> ..
30/04/2012 23:42 1,126 Aptana Studio 3.lnk
12/02/2012 18:21 870 Downloads - Shortcut.lnk
19/04/2012 22:58 1,227 eclipse - Shortcut (2).lnk
25/02/2012 13:02 949 eclipse - Shortcut.lnk
12/05/2012 09:09 42 first.js
30/04/2012 23:16 2,397 Google Chrome.lnk
15/05/2012 16:50 406 Hello.class
14/05/2012 23:44 100 Hello.java
11/03/2012 19:26 1,282 Launch WhiteSmoke - Shortcut.lnk
10/03/2012 11:05 2,394 MySQL 5.5 Command Line Client.lnk
13/05/2012 13:39 <DIR> nodeWork
21/04/2012 12:41 732 Photos Family - Shortcut.lnk
12/05/2012 03:58 <DIR> Removed From Desktop Just after Second Semes
ter
14/05/2012 23:22 518 Test1.class
14/05/2012 23:22 275 Test1.java
12/05/2012 10:10 <DIR> wep tec week 12
17/11/2011 19:47 696 Workspace - Shortcut.lnk
14 File(s) 13,014 bytes
5 Dir(s) 73,063,886,848 bytes free
C:\Users\Tariq\Desktop>java Hello
Error: Could not find or load main class Hello
C:\Users\Tariq\Desktop>javac Hello.java
C:\Users\Tariq\Desktop>java Hello
Error: Could not find or load main class Hello
C:\Users\Tariq\Desktop>
- 05-15-2012, 10:17 PM #7
Re: Compiles fine but error when try to run
Looks like the java command should find the class file or give a different error message. I can not get the error message you get. Here's what I get:
D:\JavaDevelopment\Testing\ForumQuestions7>dir Hello*
Volume in drive D is Work
Volume Serial Number is 7CE8-AEC3
Directory of D:\JavaDevelopment\Testing\ForumQuestions7
05/15/2012 04:15 PM 406 Hello.class
05/15/2012 04:15 PM 114 Hello.java
2 File(s) 520 bytes
0 Dir(s) 56,083,308,544 bytes free
D:\JavaDevelopment\Testing\ForumQuestions7>java Hello
Hi
D:\JavaDevelopment\Testing\ForumQuestions7>If you don't understand my response, don't ignore it, ask a question.
- 05-16-2012, 06:58 AM #8
Re: Compiles fine but error when try to run
What's the output from java -version?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-16-2012, 10:08 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Compiles fine but error when try to run
*sigh*
Is my post invisible?
You have CLASSPATH set in your environment variables.
That is the list of places 'java' will look for the Hello class if you do not provide a '-cp .' to the java command.
Either remove the CLASSPATH variable or use the -cp switch.Please do not ask for code as refusal often offends.
Similar Threads
-
Applet compiles and tests fine in jGrasp... blank white screen when placed into HTML
By AlphaWhelp in forum Java AppletsReplies: 6Last Post: 07-01-2011, 03:20 AM -
setBounds not working (no errors; runs and compiles fine)
By cc11rocks in forum AWT / SwingReplies: 6Last Post: 02-08-2011, 02:29 AM -
Code runs fine but get compile error
By BillyB in forum New To JavaReplies: 4Last Post: 11-29-2010, 02:18 PM -
Compiles in Netbeans, error in textpad
By Npcomplete in forum New To JavaReplies: 2Last Post: 11-21-2008, 04:50 AM -
Errors driving me crazy! although compiles fine
By irishsea2828 in forum New To JavaReplies: 1Last Post: 04-08-2008, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks