This question is likely about the same issue as this one, but it appears the asker of that one hasn\'t added enough information to receive a helpful response.
I am t
I would use gradle and the javafx plugin for that.
apply plugin: "org.openjfx.javafxplugin"
javafx {
version = "11"
modules = ["javafx.base", "javafx.controls", "javafx.graphics"
}
You are already giving an explanation of your issue:
I have not modified any VM options.
Since JavaFX 11 is not part of the JDK anymore, you have to use the JavaFX SDK (as you are doing) from here, or alternatively use Maven/Gradle to retrieve the JavaFX modules from Maven Central.
Then you need to add the SDK as a library, so IntelliJ can find the JavaFX classes.
But once you have done that, and given that the JavaFX jars are modules, you still need to do two things:
Based on your IntelliJ output, it is adding by default javafx.graphics
and javafx.base
:
--add-modules javafx.base,javafx.graphics
-p /usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.base.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.graphics.jar
(note that -p
is the same as --module-path
)
This explains why your project runs in the first case, when you don't have a control added to the scene, just the StackPane
, that belongs to the javafx.graphics
module, but fails with the posted exception when you add the Label
, that belongs to the javafx.controls
module.
This has been said a number of times: you need to set the required VM options for your project.
Start by reading the documentation at https://openjfx.io/openjfx-docs/, including the IntelliJ doc, section Non-modular projects for your IDE. And read the part 4. Add VM options.
So click on Run -> Edit Configurations, and add:
-p /usr/lib/jvm/javafx-sdk-11.0.2/lib --add-modules javafx.controls
Apply, and run, the issue will be solved.
check your JAVA_HOME, JAVA_HOME'version must be jdk9+ or jdk11+