Error: Could not find or load main class Main in Intellij IDE
Answered
Hello,
I'm new to Java and today I was trying to create a simple "HelloWorld" project in IntelliJ. Unfortunatelly when I try to run a 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 screen:
I search in stackoverflow https://stackoverflow.com/questions/42660125/java-lang-classnotfoundexception-when-running-in-intellij-idea/42660624#42660624 and intelij support forum. Change and add path, but nothing work for me.
When I try to compile a program from CMD everything is working fine. Could someone help me with it? It seems like some configuration problem in Intelij, but I cann't understand how to fix it.
Please sign in to leave a comment.
Hello,
Could you please check that compiled class is present in "out " folder. Is it possible to attach full classpath from the output?
Hello Yaroslav,
thank you for response.
Here is a screenshot from the "out" folder:
Classpath is:
And in project structure:
Sorry, I meant full classpath/command from Run tool window output. Also, could you please try to check the issue with new project without space in project name?
Hi Yaroslav Bedrov,
having the same problem since IntelliJ 2022.3.x
(works perfectly with 2022.2.x or earlier)
May have something to do with the packaging change around the Main class
Here my run command:
Actually my problem is with a DevKit plugin run configuration. I may be in the wrong thread here...
Dan Cioca Please use https://intellij-support.jetbrains.com/hc/en-us/community/topics/200366979-IntelliJ-IDEA-Open-API-and-Plugin-Development for such questions.
Same here. No longer working.
Do you also have simple "Hello World" application?
Yaroslav Bedrov
After having wasted +8 hours dealing with this today I don't feel I have any time or energy to repeat this tomorrow. It might not be straightforward to reproduce as structure might be part of it as Afrina mentioned here:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/5240746520466--Could-not-find-or-load-main-class-when-using-template-after-installing-second-JDK?page=1
I reported the issue here:
https://youtrack.jetbrains.com/issue/IDEA-318005/Error-Could-not-find-or-load-main-class-com.intellij.idea.Main-Caused-by-java.lang.ClassNotFoundException-com.intellij.idea.Main
And commented on many similar tickets, whereby this appears to be known:
https://youtrack.jetbrains.com/issue/IDEA-314787
Suggested patch but has not tried or read it:
https://dkimitsa.github.io/2023/03/08/devkit-fixes-idea2023-1/
I do not use gradle or kotlin for plugin development, and I have my reasons for that, which are valid and good.
If you want to see what is happening we can scheduele a timeslot and I can screenshare, other than that, my plugin development happened today, change by change, rebuilding, zipping manually, getting into issues, manually installing zip file while trying to get this to work as it used to.
Can not put more time into this at this time. Hope you fix this issue til next time.
I doubt any deployment relying on the old devkit actually works currently as the runtime args seems to be completely off. See the ticket I filed.
Thanks for information! Please follow https://youtrack.jetbrains.com/issue/IDEA-302414/2022.3-EAP-SDK-issue-Run-configs-created-against-a-2022.3-EAP-SDK-dont-use-the-correct-classpath.
It's in progress now.
I had a similar problem with a new (maven) project that I created with IntelliJ. The solution was to restart IntelliJ and do a maven->clean