Results 1 to 11 of 11
- 08-16-2011, 12:58 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
Could not find or load main class: c:\java\HelloWorldApp
The title of this post is the error that appeared when I attempted to run the Hello World application as outlined in the Java Tutorials.
My source file was HelloWorldApp.java (cut and pasted from the tutorial)
I compiled it with the command : javac HelloWorldApp.java
It produced a file HelloWorldApp.class
I then attempted to run the application with the command : java HelloWorldApp
It then produced the above error. I am aware that this particular problem was the subject of another posting but I cannot figure out what the proposed solution was. Can anyone help?
- 08-16-2011, 01:07 AM #2
Try the above command (make sure you get the spaces correct). If it works then read about classpath.Java Code:java -cp . HelloWorldApp
- 08-16-2011, 01:23 AM #3
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
I used the command : java -cp . HelloWorldApp
However, the error appeared exactly as before.
- 08-16-2011, 01:46 AM #4
In that case your HelloWorldApp class is not in that directory.
- 08-16-2011, 02:02 AM #5
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
Hi Junky
Thank you for being patient.
The file HelloWorldApp.class resides in C:\java
I abbreviated the command for purposes of clarity.
The full command was C:\Program Files\java\jdk1.7.0\bin\java - cp . C:\java\HelloWorldApp
- 08-16-2011, 02:08 AM #6
Go to the directory where you .class file is and type the command to run your program.
- 08-16-2011, 04:05 AM #7
Member
- Join Date
- Jul 2011
- Posts
- 14
- Rep Power
- 0
please share your code...
- 08-16-2011, 10:53 AM #8
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
Hi Junky,
Problem solved
Both instructions - java HelloWorldApp and java -cp . HelloWorldApp now work.
Apparent problem was that the instructions would not tolerate a full description of where the HelloWorldApp class file resided
A curiosity : I used a DOS PATH statement (as used in autoexec.bat files) to pick up the location of java.exe and javac.exe and make them available in any directory. Is this how it is usually done nowadays?
Thanks again!
- 08-16-2011, 11:18 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Remember: javac compiles files and java runs classes; the fact that those classes can be stored in files is coincidental. java uses the current working directory as a classpath (so -cp . is not necessary on a MS Windows system). It depends on the classloader where and how classes are found; the 'normal' system class loader can find the classes in files or in .jar file entries but nothing forbids other class loaders to load classes from databases or by emailing some super user and asking them to send the class over the wire. The classpath is just used by the default class loader and is a list of directories and .jar files that have to be searched for class files. Package names in class names are mapped to subdirectories.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-02-2012, 12:57 AM #10
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Re: Could not find or load main class: c:\java\HelloWorldApp
I just wanted to chime in here, and say that your response helped me. I have been fighting with my classpath trying to get it right, but atleast now I know that everything else worked.
Thanks
Jake
- 02-02-2012, 08:26 PM #11
Similar Threads
-
Error: Could not find or load main class HelloWorldApp (HELP)
By couch_mango in forum New To JavaReplies: 29Last Post: 02-02-2012, 08:23 PM -
Failed to load Main-Class manifest attribute from
By karq in forum New To JavaReplies: 5Last Post: 09-16-2011, 07:01 AM -
Could not find main class
By Karenthian in forum New To JavaReplies: 7Last Post: 03-30-2011, 03:02 PM -
Could not find main class
By yetty4ever in forum New To JavaReplies: 7Last Post: 02-16-2011, 07:38 PM -
Could not find main class
By Andyj in forum New To JavaReplies: 2Last Post: 10-06-2009, 12:47 AM


LinkBack URL
About LinkBacks


Bookmarks