Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 42
Like Tree1Likes

Thread: Java Could not find main class...

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

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

    Hope this image kind of shows every step I made, and the error message, my code for the program is: which works fine in the eclipse output (viewer)

    Java Code:
    import javax.swing.*;
    
    public class HelloWorld {
    	public static void main (String[] args)
    	{
    		
    		String helloWorld = " Hello World!! ";
    		JOptionPane.showMessageDialog(null, helloWorld);
    	
    	}
    }


    Uploaded with ImageShack.us

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

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

    That wasn't what I was looking for.
    Open the directory with the jar file
    Double click on the jar file
    Print screen the error message

    How did you double click on the jar file when you took the screen print?

    How many versions of the jar file and program are there?

    The one you posted in post#1 is in a package: test.
    The one you just posted shows Main-Class: HelloWorld not in a package.

    Delete all versions of the jar file and create a new one for testing.
    Last edited by Norm; 03-03-2012 at 03:14 PM.

  3. #23
    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
    That wasn't what I was looking for.
    Open the directory with the jar file
    Double click on the jar file
    Print screen the error message

    How did you double click on the jar file when you took the screen print?

    How many versions of the jar file and program are there?

    The one you posted in post#1 is in a package: test.
    The one you just posted shows Main-Class: HelloWorld not in a package.

    Delete all versions of the jar file and create a new one for testing.

    Sorry I let me do that again in post =1
    Its the same error message, what ever java program I export into a jar file it does the same message.
    Screenshot: (Started from beginning)



    Uploaded with ImageShack.us

    Regards

  4. #24
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

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

    Isn't your class in a package 'test'? Your JVM seems to be looking for a class in the default (no name) package; check the manifest entry.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

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

    The most likely error is multiple versions of a file.

    How many versions of the jar file and program are there?

    The one you posted in post#1 is in a package: test.
    The one you just posted shows Main-Class: HelloWorld not in a package.

    Delete all versions of the jar file and create a new one for testing.

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

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

    Ok, I deleted all version of my jar and created a new work space and new files I have created a new HelloWorld file etc.
    I have the same error..

    Here is my extracted java file manifest:

    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: HelloWorld
    There is no package with this new file. just the default package

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

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

    If there are no packages anywhere then that should work.
    Did you do a Search for the jar files and delete ALL of them and then create a new jar file with a manifest and a class file that don't use packages?

  8. #28
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

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

    Does the last line of your manifest file have an end-of-line character? (e.g. \r\n on an MS Windows machine or \n on a Unix/Linux machine).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #29
    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
    If there are no packages anywhere then that should work.
    Did you do a Search for the jar files and delete ALL of them and then create a new jar file with a manifest and a class file that don't use packages?
    Quote Originally Posted by JosAH View Post
    Does the last line of your manifest file have an end-of-line character? (e.g. \r\n on an MS Windows machine or \n on a Unix/Linux machine).

    kind regards,

    Jos
    Yes and No its just blank

    I just don't know why it doesn't work. If you guys wouldn't mind could i upload the .jar file? so you could take a look at the complete file?

    You could see that the manifest file is all correctly listed and if it is a problem my end, or the file..

    File name: HelloWorld.jar File size: 683 Bytes


    Thanks in advance

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

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

    It works for me:

    C:\Temp>D:\Java\jre7\bin\java.exe -jar HelloWorld.jar
    Hello World!

  11. #31
    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
    It works for me:

    C:\Temp>D:\Java\jre7\bin\java.exe -jar HelloWorld.jar
    Hello World!
    ok, does it work when you double click it?

    It works for me through the CMD, but not when i double click it. why would that be?
    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>
    Last edited by DiciWales; 03-03-2012 at 06:50 PM.

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

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

    Why are the outputs from the programs different? You still have more than one version of the jar file!!!

    What do you expect to happen when you double click on the program? There is no console to see its output.

  13. #33
    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
    Why are the outputs from the programs different? You still have more than one version of the jar file!!!

    What do you expect to happen when you double click on the program? There is no console to see its output.
    Ok so, in order for a java file to be clickable and run on its own without the CMD.. it needs to have more in it?

    could you perhaps give me an example of the minimum or what not code for a java application? so it just displays something simple as "Hello World!"

    Or point me to what I need to have a small box appear when i double click the file which "Hello World!" is displayed?

    Much appreciative of your help so far! I can't thank you enough

    (sorry for seeming really stupid, but I'm very new to java)

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

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

    in order for a java file to be clickable and run on its own
    Your program is executing but you don't see it. If the code wrote a file to disk you could see from the date on the file when it was last written to and know that the program executed.
    I need to have a small box appear
    Look at using the JOPtionPane class. It can display a small box with a message. Lots of sample code here on the forum if you do a Search.

  15. #35
    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
    Your program is executing but you don't see it. If the code wrote a file to disk you could see from the date on the file when it was last written to and know that the program executed.

    Look at using the JOPtionPane class. It can display a small box with a message. Lots of sample code here on the forum if you do a Search.
    Ok thanks so much for your help, basically that's what I wanted to know, there is nothing wrong with my code or my java installation

    Thankyou so much! Sorry for being a noob! :)

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

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

    We all were beginners.

  17. #37
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

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

    hi
    i have a similar problem.. I just want to access a data from another class through inheritance, and don't know, where to declare the accessed variable lol .. I'm pasting my program codes..
    import java.io.*;
    import java.util.*;
    public class inheritance extends bb{

    public static void main() {
    int a=1;
    System.out.println("a is "+a+"b is"+b);
    }
    class bb {
    int b=2;

    }
    }

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

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

    Please start a new thread with your problem.

  19. #39
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

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

    oh.. i dint know how to start, im checking it right now, and thx for the king reply

  20. #40
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

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

    Quote Originally Posted by noobplus View Post
    oh.. i dint know how to start, im checking it right now, and thx for the king reply
    Before you do so: check the signature of your main( ... ) method. It isn't what the JVM wants it to be to be an entry point of your program.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 3 FirstFirst 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
  •