"Could not find or load main class" when using template after installing second JDK

已回答

I was using JDK ver 8 and recently installed ver 11 additionally (Amazon coretto). In intelliJ I am just choosing desired JDK each time I create a project. It works with empty project but any time when I try to create project from "command line template" to have main method ready at the start I get the "Could not find or load main class com.company Main" error (regardless of what JDK i chose for the project but there are some differences - with correto 11 there is additional error line saying "Caused by: java.lang.ClassNotFoundException:com.company.Main). Creating new run configuration with the same main class does not help.

Any ideas what might be wrong here?

Any ideas what might be wrong here?

EDIT:

I also noticed that if I create such project from template and then delete all package folders in src folder and make new Main class from the scratch the problem still persist.

1

Hi there,

when I try to create project from "command line template"

 How do you create it? Is it a user-defined template?

See also https://www.jetbrains.com/help/idea/2022.1/configure-project-settings.html#new-default-settings

0

The problem happens with the pre defined "command line app" template (that one:https://i.imgur.com/DpVadRp.png) but I checked and created my own template (the user defined one are showing in different place than this command line app one. They are here:  https://i.imgur.com/gqsylXc.png ) and the problem occurs also with them even though they were working the moment I saved them as template (looks like it somehow did not save the run configuration?)

I just started reading the link You gave me but did not find anything yet that I can relate to my issue.

0

The problem sounds related to IDEA-184561 and IDEA-284897.

Is the <project-name>.iml file present in the project's root folder?

Does the created modules.xml file (.idea folder) contain the correct module name? (fileurl property, see e.g. below)

...
<modules>
<module fileurl="file://$PROJECT_DIR$/test_java.iml" filepath="$PROJECT_DIR$/test_java.iml" />
</modules>

Please also attach one of the created projects (entire folder), and idea.log file (Help | Show Log in...).

0

No it is not in the root folder of the project. Who organizes code like that. Wasted several hours today. Always intellij. Still not there. Will see if I can move it to test. 

0

Sorry, can not get it to work.

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

Can not get it to work ... tried moving iml folde rand the folde r... 

0

Could you please share sample project example?

0

请先登录再写评论。