Results 1 to 20 of 30
- 08-07-2011, 03:38 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
Error: Could not find or load main class HelloWorldApp (HELP)
I'm a total noob trying to learn Java so I can make games and programs.
Ill show you the steps that led to this.
-Opened Notepad and typed the "HelloWorld" source code.
-Saved file as HelloWorld.java to desktop.
-Went to Computer properties and set path to C:\"Program Files"\Java\jdk1.7.0\bin
-Opened Command Prompt
- Typed "cd Desktop".
-Typed "Javac HelloWorldApp"
-File compiles into a "HelloWorldApp.class" file.
-Typed Java HelloWorldApp
-Error: Could not find or load main class HelloWorldApp
Help :L
- 08-07-2011, 03:45 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
The class (HelloWorld), the filename (HelloWorld.java), and the class you specify to run (HelloWorld) must all agree. In your case you say you "Typed Java HelloWorldApp" but the command should have been
If you still get the "Could not find or load main class" error post a couple of things: (1) The source code (.java file) and (2) the actual output from the command line when you attempt to compile and run it.Java Code:C:\<whereever-your-desktop-is>\>java HelloWorld
[Edit] Or you may have meant the class to be HelloWorldApp in which case the moral is the same: the source file should be HelloWorldApp.java
For step by step details (in case you aren't actually following this page!): Oracle's TutorialLast edited by pbrockway2; 08-07-2011 at 03:47 AM.
- 08-07-2011, 03:53 AM #3
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
So How do I exit a.. um a section. As in (C:\) (\Desktop\)
- 08-07-2011, 03:59 AM #4
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
-Saved file as HelloWorld.java to desktop.
-Typed "Javac HelloWorldApp"
-File compiles into a "HelloWorldApp.class" file.
How did that come to be?
The basic syntax (can be modified) of the main method is as follows, but remove all *, they just indicate important parts that you might have missed:
Java Code:*public* class HelloWorldApp { *public* *static* void main(*String[]* args) { System.out.println("It works! ☺"); } }Last edited by Hibernate; 08-07-2011 at 03:59 AM. Reason: Forgot code tag
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 04:00 AM #5
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
- 08-07-2011, 04:07 AM #6
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
- 08-07-2011, 04:10 AM #7
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
But it was recognised before?
Did you try running?:
"C:\Program Files\Java\jdk1.7.0\bin\javac" HelloWorldApp.java
or (but I don't think it is necessary)
"C:\Program Files\Java\jdk1.7.0\bin\javac.exe" HelloWorldApp.javaLast edited by Hibernate; 08-07-2011 at 04:10 AM. Reason: nicer syntax
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 04:13 AM #8
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
- 08-07-2011, 04:13 AM #9
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
Ok i compiled it now. I had to type:
C:\"Program Files"\Java\jdk1.7.0\bin\javac HelloWorldApp.java
- 08-07-2011, 04:14 AM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Sorry for the repetition, but could you post the source code you are using and the actual command line output you get when you attempt to compile and run it?
[Edit] too slow ;( Glad you've got it compiled now.
- 08-07-2011, 04:15 AM #11
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
I guess there is a post here somewhere on how to do so that you just need to type javac, and not its absolute path.
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 04:16 AM #12
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
public class HelloWorldApp
{
public static void main(String[] args)
{
System.out.println("It works! ☺");
}
}
Compiles fine.
When i try to run it says: Error: Could not find or load main class HelloWorldApp
- 08-07-2011, 04:22 AM #13
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
I still cant "Run" the class file.
- 08-07-2011, 04:36 AM #14
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
java HelloWorldApp
or
"C:\Program Files\Java\jdk1.7.0\bin\javac" HelloWorldApp
It should not(!!) end with .class
If that does not work, what does it say?Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 04:37 AM #15
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
- 08-07-2011, 04:45 AM #16
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
- 08-07-2011, 02:44 PM #17
Member
- Join Date
- Aug 2011
- Posts
- 14
- Rep Power
- 0
PlZ Reply.. i have the same problem..
Hello.java:
class Hello{
public static void main(String args[]){
System.out.println("Hello...");
}
}
when compiled, its fine and gives me a .class file.
but when tried to execute the program:
Error: Could not find or load main class Hello.
I have my env variables set this way:
CLASSPATH
C:\Program Files\Java\jdk1.7.0\lib
JAVA_HOME
C:\Program Files\Java\jdk1.7.0
Path
C:\Program Files\Java\jdk1.7.0\bin;
I have jdk1.7.0 installed on my machine, but the jre is jre6 (C:\Program Files\Java\jre6). Is that a problem that versions of jdk and jre are different.
Reply would be a great help. Thanks
- 08-07-2011, 02:47 PM #18
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You may want to make a new post, rather than adding it to this one. Even if it is a similar question.
- 08-07-2011, 03:06 PM #19
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Remove the CLASSPATH variable unless you set it for some reason. Run the program with
It is the dash-cp-space-dot which sets the classpath that the java exectable will use (to the current dirctory). Using an OS variable for this purpose is not very flexible and setting the classpath to the lib directory makes no sense.Java Code:java -cp . Hello
If this does not run your program, start your own thread although for all we can tell the OP may be making the same mistake.
- 08-07-2011, 03:46 PM #20
Member
- Join Date
- Aug 2011
- Posts
- 14
- Rep Power
- 0
Thanks.It works with this command java -cp . But do I need to change any settings or so.. in order to avoid typing -cp . every time i execute a program? Do you know why I had this problem. Because generally its just the 'java' command that is used to execute a simple java program.
Thanks again for the reply..
Similar Threads
-
Error: Could Not Find Main Class. Program Will Exit
By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 09:48 PM -
runtime error 'could not find main class' ?
By ruud00000 in forum Java AppletsReplies: 5Last Post: 12-31-2010, 05:58 PM -
jar file ERROR:Could not find the main class. program will exit.
By Himanshu23 in forum AWT / SwingReplies: 3Last Post: 11-11-2010, 08:12 AM -
[SOLVED] Could not find the main class: error...
By bobleny in forum New To JavaReplies: 21Last Post: 03-02-2010, 10:53 AM -
could not find main class, the program wil exit-- error in jar file
By nishant.4545 in forum Advanced JavaReplies: 1Last Post: 07-03-2009, 08:41 PM


2Likes
LinkBack URL
About LinkBacks


Bookmarks