Results 1 to 5 of 5
- 05-28-2011, 06:41 PM #1
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
Could not find the main class: Hello. Program will exit.
I've read the other threads on this issue and none of the suggestions seem to work. I wrote the standard issue "Hello.java" source file and complied it using NetBeans. When I run it in NetBeans it outputs the string as expected.
When I navigate to the directory where Hello.class resides and issue the command: java Hello I get the error message "Could not find the main class..."
I tried java -classpath . Hello: same result
I tried java -cp . Hello: same result
Then I navigated to the folder where Hello.java resides and compiled it with the javac command and it created Hello.class in the same folder as expected. However when I enter java Hello i still get the error.
I'd appreciate some help. I am absolutely brand new to Java but I have over a decade of programming experience in SQL Server, Visual Basic, and C++. I don't understand why I can't get this to run.
Thank You
- 05-28-2011, 06:59 PM #2
Please copy and paste the full contents of the console showing the command entered and the error message.
Also enter the dir command to show the contents of the folder and include that with the above.
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.
- 05-28-2011, 07:14 PM #3
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
D:\__Dev\JavaLiang\Hello\src\hello>javac Hello.java
D:\__Dev\JavaLiang\Hello\src\hello>dir
Volume in drive D has no label.
Volume Serial Number is B2F6-63BC
Directory of D:\__Dev\JavaLiang\Hello\src\hello
05/28/2011 12:03 PM <DIR> .
05/28/2011 12:03 PM <DIR> ..
05/28/2011 12:03 PM 446 Hello.class
05/28/2011 11:36 AM 347 Hello.java
2 File(s) 793 bytes
2 Dir(s) 102,976,704,512 bytes free
D:\__Dev\JavaLiang\Hello\src\hello>java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong name: he
llo/Hello)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Hello. Program will exit.
- 05-28-2011, 07:17 PM #4
It appears that your program is in the package: hellowrong name: hello/Hello)
Either remove the package statement from your code
or give the package path to the java command.
To do that you need to move to the folder that holds the hello folder(src) and issue the java command in that folder:
java hello.Hello
- 05-28-2011, 07:29 PM #5
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
OK - I removed the package statement and it ran in the "build" folder . I also navigated to the src folder and I issued the command with the package path and it worked. Like I said, I am brand spanking new to this - hopefully Liang will explain what's going on.
Thank you very much - I am regluing my hair to my scalp.
Similar Threads
-
Could not find the main class, program will exit.
By CourseLanguage in forum New To JavaReplies: 18Last Post: 05-03-2011, 10:14 PM -
Could not find the main class, program will exit
By grottesco in forum New To JavaReplies: 7Last Post: 11-03-2010, 06:51 AM -
Could not find the main class, program will exit.
By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 10:02 AM -
Could not find the main class. Program will exit.
By XSROSSITER in forum New To JavaReplies: 0Last Post: 01-30-2010, 04:17 AM -
Could not find the main class. Program will exit.
By Carrier in forum New To JavaReplies: 1Last Post: 04-22-2009, 02:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks