Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij "Could not find or load main class"

I installed intellij and it keeps giving me error:

Could not find or load main class sample.Main

I checked many answers for similar questions and non of them worked. The program I'm trying to run:

package com.company;

public class Main {

    public static void main(String[] args) {
        System.out.printf("hello");
    }
}

enter image description here

Run Configuration enter image description here

Settings enter image description here

enter image description here

enter image description here

"out" folder is not getting created. Full run command used by intellij after expanding "..."

"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:E:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.1\lib\idea_rt.jar=51072:E:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar" com.company.Main

like image 683
Anthony J. Avatar asked Aug 17 '18 19:08

Anthony J.


People also ask

How do I specify main class in IntelliJ?

Once you have a project set up with source packages and test packages, you can right-click on one of those packages and choose New > Java Class from the context menu: Then, in the New Java Class dialog box, type in a name for the new class and press Enter or Return.


1 Answers

Thanks to CrazyCoder, I could find the root of the problem. Intellij is using wrong iml file in "modules.xml" file. Change the iml value in modules.xml manually and rebuilding the project fixed the problem. enter image description here

Of course this is just a work around. I think I have problem my intellij as it always using wrong iml file for all new projects.

like image 80
Anthony J. Avatar answered Oct 05 '22 05:10

Anthony J.