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

11,238

After long and stressful time trying to find solution I FINALLY discovered what was wrong. So as you see for some reason NetBeans uses JDK7 as default but to run .jar file my system uses JRE6. So I changed my NetBeans settings to use and compile with JDK6 and got it to work. Also my code had diamond operator which are not supported in JDK6.

Share:
11,238
Rohit Malish
Author by

Rohit Malish

Updated on June 04, 2022

Comments

  • Rohit Malish
    Rohit Malish almost 2 years

    Ok, just listen to me before you close this thread or answer somethin completely out of topic. I have checked absolutely every solution. I have read every other similar SO topic and tried everything they say there. I'm using NetBeans and yes it does run my program succesfully ALSO my command promt RUNS PERFECTLY my program. I get "Could not find the main class: Main. Program will exit." ONLY when I am trying to double click jar. YES I HAVE Manifest file and it tells where my Main class is. I have even tried to create new project with only Main class which creates just one frame, and then build it, but still same error.

    Here is my Main class (only class) which is in default package:

    public class Main {
    
        public static void main(String[] args) {
            JFrame frame = new JFrame("Test");
            frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.setBounds(450, 170, 400, 400);
        }
    }
    

    and here is manifest file:

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.2
    Created-By: 1.7.0_02-b13 (Oracle Corporation)
    Class-Path: 
    X-COMMENT: Main-Class will be added automatically by build
    Main-Class: Main
    
  • Admin
    Admin over 11 years
    This worked for me. I had an older version 6 of icedtea still installed on Ubuntu. I removed the old jdk and jre packages for version 6.