Sample JavaFX Project - Error: Could not find or load main class sample.Main

Answered

So I just created a new sample JavaFX project from New > Project > JavaFX > JavaFX Application.

Nothing added. Nothing changed.

Clicking on Run > Run Main gives the error `Error: Could not find or load main class sample.Main`.

Any help?

5 comments
Comment actions Permalink

Try using JDK 8.

See https://stackoverflow.com/a/52470141/104891 if you want to use Java 11.

If the issue persists, attach a sample project to reproduce via https://intellij-support.jetbrains.com/hc/articles/206869619.

0
Comment actions Permalink

What if you are using JDK 8 and you still have the same issue.  It not hard to reproduce.  Just install IntelliJ with all default settings, create a JavaFX program, Click Run.  You get this error.

"C:\Program Files (x86)\Java\jdk1.8.0_201\bin\java.exe" -javaagent:C:\Users\steve\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\183.5429.30\lib\idea_rt.jar=61987:C:\Users\steve\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\183.5429.30\bin -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-32.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.8.0_201\jre\lib\rt.jar" sample.Main

Error: Could not find or load main class sample.Main

If you click on Configuration to set the Main class:  (by default sample.Main is where main exists).  But you can't select it.  What is going on.

 

0
Comment actions Permalink

Please see https://stackoverflow.com/a/42660624/104891.

Share a sample project if the issue persists.

0
Comment actions Permalink

I have the same problem.

I made 2 steps:

1. Creat directory "out" in your Project.

2. Set that directory in Project compiler output:

File ->  Other Settings -> Structure forNew Projects...

Then Browse to directory "out" that just create.
Push Apply and Ok buttons.

0
Comment actions Permalink

> 2. Set that directory in Project compiler output:

Structure for the new project doesn't affect the settings of the current project, use the different dialog: https://www.jetbrains.com/help/idea/project-structure-dialog.html .

1

Please sign in to leave a comment.