Error: Could not find or load main class Main in Intellij IDE

已回答

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.

2

Hello,

Could you please check that compiled class is present in "out " folder. Is it possible to attach full classpath from the output?

0

Hello Yaroslav,

thank you for response.

Here is a screenshot from the "out" folder:

Classpath is:

And in project structure:

 

0

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?

0

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:

"C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\jbr\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:61989,suspend=y,server=n -Xmx1024m -Xms256m -XX:MaxPermSize=250m -ea -Dplugin.classloader.debug=true -Djava.system.class.loader=com.intellij.util.lang.PathClassLoader -Didea.config.path=D:\data\IntelliJIdea23.1\system\plugins-sandbox\config -Didea.system.path=D:\data\IntelliJIdea23.1\system\plugins-sandbox\system -Didea.plugins.path=D:\data\IntelliJIdea23.1\system\plugins-sandbox\plugins -Didea.classpath.index.enabled=false -Djdk.module.illegalAccess.silent=true --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.base/jdk.internal.vm=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/sun.nio.fs=ALL-UNNAMED --add-opens=java.base/sun.security.ssl=ALL-UNNAMED --add-opens=java.base/sun.security.util=ALL-UNNAMED --add-opens=java.desktop/java.awt=ALL-UNNAMED --add-opens=java.desktop/java.awt.dnd.peer=ALL-UNNAMED --add-opens=java.desktop/java.awt.event=ALL-UNNAMED --add-opens=java.desktop/java.awt.image=ALL-UNNAMED --add-opens=java.desktop/java.awt.peer=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED --add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.desktop/sun.awt.datatransfer=ALL-UNNAMED --add-opens=java.desktop/sun.awt.image=ALL-UNNAMED --add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED --add-opens=java.desktop/sun.awt=ALL-UNNAMED --add-opens=java.desktop/sun.font=ALL-UNNAMED --add-opens=java.desktop/sun.java2d=ALL-UNNAMED --add-opens=java.desktop/sun.swing=ALL-UNNAMED --add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED -Didea.required.plugins.id=DBN -Didea.platform.prefix=Idea -Didea.plugin.in.sandbox.mode=true -javaagent:D:\data\IntelliJIdea22.3\system\captureAgent\debugger-agent.jar=file:/C:/Users/CiocaD/AppData/Local/Temp/1/capture.props -Dfile.encoding=windows-1252 -classpath "D:\data\IntelliJIdea22.3\system\captureAgent\debugger-agent.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\log4j.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\jdom.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\trove4j.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\openapi.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\util.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\util_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\bootstrap.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\idea.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\3rd-party-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 23.1 CE\lib\jna.jar;C:\Program Files\JetBrains\IntelliJ IDEA 22.3\lib\idea_rt.jar" com.intellij.idea.Main

 

0

Actually my problem is with a DevKit plugin run configuration. I may be in the wrong thread here... 

0

Same here. No longer working.

0

Do you also have simple "Hello World" application?

0

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. 

0

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

1

请先登录再写评论。