Page 2 of 2 FirstFirst 12
Results 21 to 40 of 40
Like Tree1Likes

Thread: Could not find the main class, program will exit.

  1. #21
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

  2. #22
    jgcube is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    Ok what I did: I created a new file to be my new workspace and I imported all my projects and it is now working.
    I still would like to know why this error occured, but now I can code the application for my school.
    Thx for the feedback xcallmejudasx

  3. #23
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    No problems. Sorry I can't help with the actual error. Try the Eclipse forums or put a bug report in, see if anybody else had similar issues or knows what was wrong.

  4. #24
    gutfeeling's Avatar
    gutfeeling is offline Member
    Join Date
    Jan 2009
    Location
    Sydney, Australia
    Posts
    1
    Rep Power
    0

    Default

    I had this problem today in Eclipse 3.3.1. To solve I did the following:
    1. Right-click the project & select Properties.
    2. Select Run/Debug Settings.
    3. Under 'Launch configurations for...', select the desired item (class, maybe project etc), and click Edit.
    4. Select the JRE tab.
    5. Select Alternate JRE and choose the JRE.

    Probably the above could also be solved by changing the JRE used for the entire Workspace (wherever that setting is set), but I have a couple of different projects which are using different JRE versions so I only wanted to change the JRE for this one project.

  5. #25
    wonder is offline Member
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default

    I see the same error "Could not find the main class. Program will exit" when I run "javaw -jar ./MyJar.jar" in a command window, while when I run the jar by "java -jar ./MyJar.jar", I get the exception "Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file" . However, the same jar file could be run by either java or javaw on another machine. It turns out that the problem is the jar/class file is compiled by JDK 1.6, while on the first machine, JRE 1.5 was installed as default java VM. That causes the problem.

    It's really hard to find the true reason by just reading the error msg from javaw, instead of java.

  6. #26
    karthikeyanrv is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default

    Had the issue, "gutfeeling" suggestion worked for me. Thanks

  7. #27
    slick is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default

    "Java virtual machine... Could not find the main class.."

    Next time try to install java software out of "C:/Program files" location, purely "C:/Java/..". The whitespace can be the issue for your error.

    GL

  8. #28
    mann is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default version mismatch

    check the eclipse configuration , jdk version applied.

    This is only due to mismatch of the versions.

  9. #29
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by cruxblack View Post
    It's not very helpful for begginers to use an IDE without understanding concept

    right. if you enter "Managing the Java classpath (Windows)" in google you will get inter alia a link to the ibm-library, where this concept is very well explained. regrettably i could not post the link, because my numberOfPosts < 20.

  10. #30
    sEver is offline Member
    Join Date
    Dec 2009
    Location
    Cracow/Poland
    Posts
    1
    Rep Power
    0

    Default

    Quote Originally Posted by Sircedric88 View Post
    You should use Eclipse
    Eclipse.org
    Well, as a matter of fact I am, and I just got the same error as original poster. It happened after I imported projects copied from another workspace into my home workspace. Resetting the Project's 'Properties->Run/Debug Settings' to default fixed the issue.

  11. #31
    johder is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default Exception in thread "main" ... Could not find the main class

    Hi,

    I have written a easy Java program, taken from a book

    import javax.swing.*;

    public class Hej {
    public static void main (String[] arg){
    String name;
    String hello;
    namn = JOptionPane.showInputDialog("What is your name?");
    hello = "Welcome" + name;
    System.out.println(hello);
    System.exit(0);
    }
    }

    I can compile the program, but when I try to run ut, I got following error:

    Exception in thread "main" java.lang.NoClassDefFoundError:Hi
    Caused by: java.langClassNotFoundException: Hi
    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>
    at java.lang.ClassLoader.loadClassInternal<Unknown Source>
    Could not find the main class: Hi. Program will exit.

    Does this have to do with the PATH or CLASSPATH settings?

    Please help.

    Thanks!

    Johanna

  12. #32
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    You got a syntax error here--

    namn = JOptionPane.showInputDialog("What is your name?");

    shouldn't it be name?

  13. #33
    johder is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    oh I missed that, but that is not the error, that cuased the exception :-(

    /johanna

  14. #34
    johder is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    I have written a easy Java program, taken from a book

    import javax.swing.*;

    public class Hi {
    public static void main (String[] args){
    String name;
    String hello;
    name = JOptionPane.showInputDialog("What is your name?");
    hello = "Welcome" + name;
    System.out.println(hello);
    System.exit(0);
    }
    }

    I can compile the program, but when I try to run ut, I got following error:

    Exception in thread "main" java.lang.NoClassDefFoundError:Hi
    Caused by: java.langClassNotFoundException: Hi
    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>
    at java.lang.ClassLoader.loadClassInternal<Unknown Source>
    Could not find the main class: Hi. Program will exit.

    Does this have to do with the PATH or CLASSPATH settings?

    Please help.

    Thanks!

    Johanna

  15. #35
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    please check whether current directory got included in your path.
    Ramya:cool:

  16. #36
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    please check whether current directory got included in your path.
    classpath, ramya, classpath!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  17. #37
    johder is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default classpath and path

    Hi,

    my personal classpath looks like:
    C:\Java\jdk1.6.0_17\bin

    The system classpath looks like:
    C:\Java\jre6\lib\ext;C:\Java\jre6\bin;C:\Java\jdk1 .6.0_17\lib

    My system path looks like:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;C:\Program Files\CyberLink\Power2Go;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Common Files\DivX Shared\;C:\Program Files\QuickTime\QTSystem\;C:\php;C:\SUN\SDK\jdk\bi n;C:\Java\jdk1.6.0_17/bin

    Is the system classpath wrong?

    /Johanna

  18. #38
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    The path is fine, the system classpath is useless. The classpath has to cantain the diectory in which your Hi.class file is located.
    java -cp .;<any additional jar files or directories> Hi


    Note: the period in that line is the current directory.

    Some resources:
    http://wiki.java.net/bin/view/Javapedia/ClassPath
    http://java.sun.com/j2se/1.5.0/docs/...ngclasses.html
    http://java.sun.com/j2se/1.5.0/docs/...classpath.html
    http://java.sun.com/j2se/1.5.0/docs/...classpath.html
    http://www-106.ibm.com/developerwork...vaclass-i.html
    Last edited by PhHein; 01-05-2010 at 04:32 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  19. #39
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by jgcube View Post
    Recompiling the .class file doesnt work and I cant either create a new project with a single class with a main without this error.
    Should I uninstall then install a new eclispe?
    If you can't run java -version and javac -help on your machine you it's clear that eclipse is making problems too, because eclipse is build on java. so try to fix your java/javac problem first or you will install and uninstall eclipse thousend of time without success. that's my advice.

  20. #40
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by johder View Post
    Please help.
    I copied your java-code in a folder \TestProject\src\Hi.java and then I compiled it so that the class-file landed in \TestProject\bin\Hi.class

    Then from the project-root resp. \TestProject I entered java -cp bin Hi

    and the code run. If you have all files (*.java, *.class) in the same folder then change to that folder and enter java -cp . Hi

    The . after -cp tells the jvm to look for the class Hi is in the actual folder. I tested even this version and your Hi started successfully.

    As long you tell the jvm in which folders the classes are it doesn't matter from where you start the class. but perhaps it's easier for you to change to that folder and start with -cp .

    Try... Good Luck
    Last edited by j2me64; 02-19-2010 at 11:15 AM.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. Replies: 8
    Last Post: 04-22-2008, 04:21 AM
  3. Replies: 1
    Last Post: 08-07-2007, 07:16 AM
  4. problems to find the main method
    By christina in forum Eclipse
    Replies: 2
    Last Post: 08-06-2007, 08:51 PM
  5. How to exit the program..
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 06:56 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
  •