13

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

Anthony J.
  • 375
  • 1
  • 5
  • 14
  • Did the com.company file and import appear there on its own? I don't think that's supposed to be there when running IntelliJ on a fresh install. – Howard P Aug 17 '18 at 20:00
  • Did you try rebuilding? – shmosel Aug 17 '18 at 20:02
  • Check the output directory has write permissions, check build.log for errors (https://intellij-support.jetbrains.com/hc/articles/207241085), see also http://stackoverflow.com/a/42660624/104891 answer. What's the output path you are masking out on your screenshots? – CrazyCoder Aug 17 '18 at 20:02
  • @HowardP I created sample command line application that comes with intellij. – Anthony J. Aug 17 '18 at 20:49
  • @shmosel I tried rebuilding and it didn't fix the issue. – Anthony J. Aug 17 '18 at 20:52
  • @CrazyCoder I checked that answer before and all suggested options didn't fix my issue. Intellij has write access to output folder. The masked output folder is just in same location as project itself. There is no need for masking as you can see the path in intellij title. – Anthony J. Aug 17 '18 at 20:53
  • @AnthonyJ. share the logs (https://intellij-support.jetbrains.com/hc/articles/207241085). – CrazyCoder Aug 17 '18 at 20:53
  • @CrazyCoder please download them from we.tl/t-8rouVyKTnZ – Anthony J. Aug 18 '18 at 05:47
  • `Module 'untitled104' is skipped: e:\Projects\JavaFX\CompleteDeveloper\untitled1\untitled104.iml doesn't exist ` The project seems to be corrupted and the module file is not found by the compiler. Try creating the new project from scratch. If it doesn't help, zip and share the entire project directory ([Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)). – CrazyCoder Aug 18 '18 at 05:49
  • That was actually new project. Anyway, I again created simple command line project and still same issue. I checked log and it gives exactly same problem "untitled104.iml" doesn't exist. The "iml" file of the new project is named "Stackoverflow.iml" not "untitled104.iml"! – Anthony J. Aug 18 '18 at 06:24
  • I had a similar problem; I solved it by reinstalling IntelliJ - can't figure out why my former installation was awry... – potame Oct 12 '18 at 13:33
  • my default IML file had inside the – JJS Oct 16 '18 at 19:15

5 Answers5

8

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.

Community
  • 1
  • 1
Anthony J.
  • 375
  • 1
  • 5
  • 14
1

I just faced error in my IntelliJ also, for me all the setting looks good even though it was not working. I removed main.iml file and right click and run program. Again it's created new main.iml and works fine.

parrotjack
  • 432
  • 1
  • 6
  • 18
0

I struggled to find an answer to the same issue, eventually, I hope that was the reason, I deleted the content of the "out" directory and re-run. It helped.

nomadus
  • 859
  • 1
  • 12
  • 28
0

[June 2020 Answer] Works with all Intellij versions.

Select File menu Project settings. (or CMD + ; in mac)

Click Artifacts -> New Jar (+) -> Empty

( Now you will get option to create Manifest file) enter image description here

Then Manually add the libraries and META-INF path which should be inside resources directory.

Make sure to include Module Output Folder also inside jar.

enter image description here I created a video to help this out https://www.youtube.com/watch?v=wPGSas_f0ts

abdul rashid
  • 730
  • 9
  • 21
0

Simplest solution: Restart your device.

Have you reinstalled IntelliJ? I think there's an error in IntelliJ configuration files.

It creates incorrect IML configurations. You can get rid of it by creating a Gradle project.

I'm sure you won't face this error in a Gradle project. If you do, please don't have a look at the first solution. Jump to the second one.

First Solution

  1. Try to uninstall with an uninstallation tool like IobitUninstaller or any other you like.
  2. Restart your device.
  3. Open the JetBrains directory which was created in the ProgramFiles folder.
  4. If there's a "JetBrains" folder, then delete it.

(Remember step 4 will delete all of your IntelliJ products. So if you have any other IntelliJ product, you can only delete the terrible product.)


  1. Then open up the ProgramData folder in your System drive, then look for another JetBrains folder.
  2. Delete it too.

(Remember step 6 will delete all of your IntelliJ products. So if you have any other IntelliJ product, you can only delete the terrible product.)

  1. Then access the AppData folder which is hidden under your windows user account. (Ex: "C:/Users/user/AppData/").
  2. Then go to the "Local" folder and look for the JetBrains folder.
  3. Delete if there's one.
  4. Then go back to the AppData folder again and go to "LocalLow" and do the same.
  5. Then back once, go to the Roaming folder, and do the same again.

So you've completely uninstalled the JetBrains software.

  1. Then access JetBrain's official website, www.jetbrains.com, and download the latest IntelliJ Idea version.
  2. Then install it.
  3. Restart your device.
  4. Try to create a HelloWorld project and try to run it.

Note: Try to search for remove Registry files too. But I think this isn't needed.

If this way didn't work for you. then we can have a look at the second solution.

Second Solution.

  1. Remove IntelliJ again as we discussed. (Have a look at solution 1).
  2. Install a beta build and try again.

If it doesn't work either, then the third way.

Third Solution.

  1. Uninstall your JDK. 2) Reinstall it. GrallVM is recommended.

Last Solution.

!) If no way of these worked for you. Then you may like to reset your device!