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 trying to run a JavaFx application with JDK and JavaFx SDK version 11.0.2.
This code works exactly as expected, producing an empty window:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
public void start(Stage primaryStage) throws Exception {
StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 420, 420));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
However, if I try to add a label to the StackPane
, an exception is thrown.
import ...
import javafx.scene.control.Label;
public class Main extends Application {
public void start(Stage primaryStage) throws Exception {
StackPane root = new StackPane();
root.getChildren().add(new Label("42"));
primaryStage.setScene(new Scene(root, 420, 420));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The stack trace it produces looks like this (line 13 in Main is where the Label is created):
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module @0xbbd2743) cannot access class com.sun.javafx.scene.layout.RegionHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene.layout to unnamed module @0xbbd2743
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at javafx.scene.control.Control.<clinit>(Control.java:86)
at sample.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application sample.Main
I am running a recent version of IntelliJ Idea on Kubuntu. I downloaded the Oracle JDK as well as JavaFX, from the official websites
I put javafx-sdk-11.0.2
in the directory /usr/lib/jvm/
and jdk-11.0.2
is in the same directory.
In IntelliJ Idea, I believe I have correctly chosen the JDK, and I have added /usr/lib/jvm/javafx-sdk-11.0.2/lib
as a library.
IntelliJ Idea is using this command to launch the Application (split up for readability):
/usr/lib/jvm/jdk-11.0.2/bin/java
-Djava.library.path=/usr/lib/jvm/javafx-sdk-11.0.2/lib
--add-modules javafx.base,javafx.graphics
--add-reads javafx.base=ALL-UNNAMED
--add-reads javafx.graphics=ALL-UNNAMED
-javaagent:/opt/jetbrains/idea-IU-183.4886.37/lib/idea_rt.jar=36031:/opt/jetbrains/idea-IU-183.4886.37/bin
-Dfile.encoding=UTF-8
-classpath
/home/rm/IdeaProjects/JfxPlayground/out/production/JfxPlayground
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/src.zip
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx-swt.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.web.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.base.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.fxml.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.media.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.swing.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.controls.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.graphics.jar
-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
sample.Main
I have not modified any VM options.
How can I fix this error? Is it a bug in JavaFx?
Question&Answers:
os