Results 1 to 5 of 5
  1. #1
    tmulherin is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,456
    Rep Power
    25

    Default

    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.

  3. #3
    tmulherin is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    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.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,456
    Rep Power
    25

    Default

    wrong name: hello/Hello)
    It appears that your program is in the package: 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

  5. #5
    tmulherin is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    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

  1. Could not find the main class, program will exit.
    By CourseLanguage in forum New To Java
    Replies: 18
    Last Post: 05-03-2011, 10:14 PM
  2. Could not find the main class, program will exit
    By grottesco in forum New To Java
    Replies: 7
    Last Post: 11-03-2010, 06:51 AM
  3. Could not find the main class, program will exit.
    By aryubi in forum New To Java
    Replies: 39
    Last Post: 02-19-2010, 10:02 AM
  4. Could not find the main class. Program will exit.
    By XSROSSITER in forum New To Java
    Replies: 0
    Last Post: 01-30-2010, 04:17 AM
  5. Could not find the main class. Program will exit.
    By Carrier in forum New To Java
    Replies: 1
    Last Post: 04-22-2009, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •