Results 1 to 12 of 12
  1. #1
    Bodachi is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Could not find the main class: main. Program will exit

    I'm currently running in Eclipse and the code I have ran fine on the University computer but now that I'm running it on my home computer it throws out this error

    "Could not find the main class: main. Program will exit."

    Java Code:
    java.lang.UnsupportedClassVersionError: main : Unsupported major.minor version 51.0
    	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(Unknown 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)
    Exception in thread "main"
    I can't figure out why. Someone please help me.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Could not find the main class: main. Program will exit

    Unsupported major.minor version 51.0
    It looks like your Java runtime is older than the class you are trying to run.

    Update your Java. Or check that you have configured Eclipse to output code suitable for your existing runtime version, and recompile everything.

  3. #3
    Bodachi is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Re: Could not find the main class: main. Program will exit

    Quote Originally Posted by pbrockway2 View Post
    Or check that you have configured Eclipse to output code suitable for your existing runtime version, and recompile everything.
    How can I check that?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Could not find the main class: main. Program will exit

    Since that's specific to the IDE, I shall move this thread from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Could not find the main class: main. Program will exit

    Java Code:
    java -version
    at the console (/command line/terminal/dos prompt) will print the version of the Java runtime on your path. (A subtle point is that you can have multiple runtimes installed. It is, perhaps, best not to when you are learning.)

    In Eclipse Indigo you can right click an entry in the "Package Explorer" and select "Properties". The "Java Compiler" entry will tell you which version of java you are compiling for.

    For instance, taking a random entry from Eclipse I see "1.6" as the value for "Generated .class files compatability". From Eclipse's main menu under "Window->Preferences" selecting "Java" and then "Installed JREs" on the left tells me that I have jre7 installed. At the console I also see Java7. The important thing is that 7>6 so that my project will build and run correctly in Eclipse.

    ---

    [Edit] This raises another point. If the number of source files is not large, consider building and running from the command line, ie not using an IDE at all.

    (and thanks db)
    Last edited by pbrockway2; 10-28-2012 at 09:19 PM.

  6. #6
    Bodachi is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Re: Could not find the main class: main. Program will exit

    I've set it up to run using Java Runtime 7. Checked to see what version I am using via the command line, it says "1.7.0_09". Now when I go to run my code it says "The specified JRE installation does not exist"

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Could not find the main class: main. Program will exit

    What location does it report for the JRE 7? Check that the JRE really is there.

    Also the "Installed JREs" section of the "Preferences" lets you add JREs with a wizard that will let you search for and use the actual location.

  8. #8
    Bodachi is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Re: Could not find the main class: main. Program will exit

    I've check and the JRE is in the same location that Ecilpse is looking at.

    Could not find the main class: main. Program will exit-jre.jpg

    Just as a note when I first set up JRE I used this guide.


    Setting up JDK on you computer: So You Can Begin Java Programming - mybringback

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Could not find the main class: main. Program will exit

    That's not hte JRE you're pointing at, that's the JDK.
    There's a jre folder underneath that one.
    Please do not ask for code as refusal often offends.

  10. #10
    Bodachi is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Re: Could not find the main class: main. Program will exit

    Ah that is what I had it on in the first place but switched it to see if it changed anything but I still got the same error. So I've now switched it back and still get the same error.

  11. #11
    Bodachi is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Re: Could not find the main class: main. Program will exit

    Thanks for the trying to help but I may have to abandon Eclipse for now, until I can get it working. Any other ideas for fixing it would still be appreciated but I've got work, I need to hand in this week. So any suggestions for an alternative to Eclipse for Java development for Windows would be lovely.
    Last edited by Bodachi; 10-29-2012 at 08:57 PM.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Could not find the main class: main. Program will exit

    If, on running your app through Eclipse, you are getting that error in the OP then that means your execution environment is wrong compared to your compilation environment.

    The execution is determined by Run Configuration, which you can get to by right clicking your project, selecting Properties->Run/Debug Settings and picking the launch config in the list. Edit that, assigning the correct JRE in the JRE tab.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 4
    Last Post: 05-28-2011, 07:29 PM
  2. 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
  3. 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
  4. 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
  5. 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

Posting Permissions

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