Error: Could not find or load main class com.company.Main Caused by: java.lang.ClassNotFoundException: com.company.Main

Answered

Hello, 

For some unknown reason, when I try to run any new project, I got this error: Error: Could not find or load main class com.company.Main
Caused by: java.lang.ClassNotFoundException: com.company.Main
Here is a screenshot:


I have tried a few things but without luck. 
I would be very happy if someone helps me with this.
Thank you

1
10 comments

Hello Serge,

Thank you for your answer. 

I am not quite familiar but I think it has something to do with " Base Package". Because the error came after I  changed the Base Package for another exercise I was doing.

This is what I found as an error:

And there is another thing: 

 

0

You are affected by this bug: https://youtrack.jetbrains.com/issue/IDEA-184561 .

As a workaround don't create the project from template, just create an empty Java project.

Another workaround is to edit .idea/modules.xml file and change untitled104.iml with the actual .iml file name that corresponds to your module name.

3

Hello Serge,

Creating a New Project but no from a template works. 

Thank you for your solution.

0

Experiencing the same issue with Intellij IDEA 2021.1.1  :-/ 

0

Gary Chike

Please note that there is still an issue with multiple module templates: IDEA-107257

If your problem is different, please file a separate issue with exact steps to reproduce the problem (screenshots will be helpful). Zip & attach your project folder to it including the .idea configuration folder and IDE logs (Help | Collect Logs and Diagnostic Data). Thank you.

0

Hi Arina, I resolved the issue by uninstalling and reinstalling the application and not importing previous settings. It’s working now. Thank you, Gary

0

As of Aug 1, 2021, I still see this issue. I am trying to use IntelliJ first time. I have high expectations for this IDE. My goal is to create a simple "Hello World" java application and test it with a template. All I did is created a project from a template and it did not work. As someone suggested I created a project without using a template it worked fine with some configuration changes though. My expectation is that with the simple steps I should be able to start basic development. I am not impressed with this now. Hopefully, my opinion will change later, once I gain some experience.

0

I also still see this same issue. Just downloaded 2021.2 Community Edition to learn Java, and the first exercise was to create a new project from template, and now nothing will work. It just keeps asking about "untitled104.iml". Deleting and reinstalling (yes, even without importing previous settings) did not help.

0

A big thanks to Serge Baranov. I was able to resolve this issue with his instructions.

0

Please sign in to leave a comment.