Page 1 of 3 123 LastLast
Results 1 to 20 of 42
Like Tree1Likes

Thread: Java Could not find main class...

  1. #1
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Java Could not find main class...

    Ok I've searched and searched everywhere and just don't know where to look next!

    Right so I'm using eclipse and have named my files the same as my project for example HelloWorld.java and my public class is HelloWorld, I exported the project as a executable java file through eclipse.. So I thought great! This will run on it's own! but no.... I've tried and tried and just can't seem to fix it!

    So my problem!

    I've double checked my MANIFEST.MF file loads of times and my file names etc.. here is my manifest file..

    Java Code:
    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: test.HelloWorld
    And my java file


    Java Code:
    package test;
    
    public class HelloWorld {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		System.out.print("Hello world");
    
    	}
    
    }
    Now I have no idea why this won't run or work.. I keep getting the message: " Could not find the main class. HelloWorld. program will exit"

    Why oh Why is this happening? For what I can see my files are in the right places within the HelloWorld.jar file that i exported using Eclipse so it should be fine??

    Anyhoot, hope you can understand any help is greatly appreciated as I don't know what I'm doing wrong!!

    Thanks in advanced!!

    /Diciwales

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

    Default Re: Java Could not find main class...

    Try running it in a command prompt window and see if you get a more complete error message.
    Open a command prompt window, change to the folder with the jar file and enter:
    java -jar <THEJARFILENAME>.jar

    If on Windows:
    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
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    Quote Originally Posted by Norm View Post
    Try running it in a command prompt window and see if you get a more complete error message.
    Open a command prompt window, change to the folder with the jar file and enter:
    java -jar <THEJARFILENAME>.jar

    If on Windows:
    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.
    Thanks,

    It works exactly fine with no error messages in CMD and displays

    HelloWorld

    Exactly how it should..

    Thanks in Advanced

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

    Default Re: Java Could not find main class...

    Is that output from the program you posted? The text of the output is different.
    HelloWorld
    vs
    Hello world

    Details are important in programming.

  5. #5
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    Quote Originally Posted by Norm View Post
    Is that output from the program you posted? The text of the output is different.
    HelloWorld
    vs
    Hello world

    Details are important in programming.
    No it was displayed Hello World, I just typed it wrong from the cmd here is it selected all

    :
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Administrator>java -jar HelloWorld.jar
    Hello world
    C:\Users\Administrator>


    Regards

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

    Default Re: Java Could not find main class...

    What happened to the error message you were getting?

  7. #7
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    The error message is still there.. it happens when i double click the application

    so confused.. just uninstalled and re-installed java.. no luck

    Regards

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

    Default Re: Java Could not find main class...

    What version of Windows are you on?
    Do you know about the registry and the registry editor?
    The registry contains the commandline the OS uses when it executes files.
    Here is the registry contents for .jar files on my XP machine:

    [HKEY_CLASSES_ROOT\jarfile\shell\open\command]
    @="\"C:\\Program Files\\Java\\jre1.6.0_07\\bin\\javaw.exe\" -jar \"%1\" %*"

  9. #9
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    Hi i'm on windows 7,

    how do i find the registry contents for .jar files using CMD?

    Thanks again for your help so far ! much appreciated

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

    Default Re: Java Could not find main class...

    Execute the regedit command. It has a windows explorer like interface. Do a Find for .jar. It wiil be in a long list of all the extensions that windows knows about. The right hand window will show (Default) on the left and will have a name in the Data column. On my system the name is jarfile.
    Do a Find for the name you see there. Under that name will be shell and command. Open command and see if it looks a little like what I posted in #8.
    Use the export menu item to export the contents to a file that you can EDIT/not merge and post here.

  11. #11
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    Quote Originally Posted by Norm View Post
    Execute the regedit command. It has a windows explorer like interface. Do a Find for .jar. It wiil be in a long list of all the extensions that windows knows about. The right hand window will show (Default) on the left and will have a name in the Data column. On my system the name is jarfile.
    Do a Find for the name you see there. Under that name will be shell and command. Open command and see if it looks a little like what I posted in #8.
    Use the export menu item to export the contents to a file that you can EDIT/not merge and post here.
    Ok I Think I have done that..
    here is what it looks like..

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\.jar]
    @="jarfile"
    I assume that is wrong? What must it be ? what must it link too?

    Thanks again! your help is much appreciated!

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

    Default Re: Java Could not find main class...

    You didn't follow all the instructions. You need to do two Finds.
    The first for ".jar" which you did and got the "jarfile" value. That looks OK.

    Now you need to do the second Find for "jarfile" which will have the command line.

  13. #13
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    ok sorry, here is the next part


    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\jarfile]
    @="Executable Jar File"

    [HKEY_CLASSES_ROOT\jarfile\shell]

    [HKEY_CLASSES_ROOT\jarfile\shell\open]

    [HKEY_CLASSES_ROOT\jarfile\shell\open\command]
    @="\"C:\\Program Files (x86)\\Java\\jre6\\bin\\javaw.exe\" -jar \"%1\" %*"
    Thanks again

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

    Default Re: Java Could not find main class...

    That looks a lot like mine.

    Is your PC 64bit or 32bit? I forget what the (x86) in the path means.

  15. #15
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    64bit

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

    Default Re: Java Could not find main class...

    What is the PATH environment set to? Open a command prompt and enter: path
    Does it have a pointer to the same bin folder that is in the command line in the registry?

  17. #17
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Administrator>path
    PATH=C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;
    C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Sys tem32\WindowsPowerShell\v1.0\

    C:\Users\Administrator>
    that's what is displayed when I type Path into the CMD

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

    Default Re: Java Could not find main class...

    What version of java do you get when in a CMD window? Enter:
    java -version

  19. #19
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: Java Could not find main class...

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Administrator>java -version
    java version "1.7.0_03"
    Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
    Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

    C:\Users\Administrator>
    Regards

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

    Default Re: Java Could not find main class...

    That's all the ideas I have for finding a problem. I don't know where to go next.


    Click to open the jar file and Screen print the error message and post the image

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 10
    Last Post: 02-02-2012, 08:26 PM
  2. Could not find the main class: java. Program will exit
    By thewonkits in forum New To Java
    Replies: 3
    Last Post: 01-11-2012, 11:56 AM
  3. Replies: 7
    Last Post: 01-01-2012, 12:29 PM
  4. Error: Could not find or load main class Ops.java
    By Javasubbu in forum New To Java
    Replies: 4
    Last Post: 10-05-2011, 10:52 PM
  5. Replies: 4
    Last Post: 08-22-2011, 03:42 PM

Posting Permissions

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