How to fix JavaFX IllegalArgumentError: cannot access class [duplicate] - java

I am totally new in javafx!!
I tried a very very simple code and I got stuck.
when I tried to add a button to the layout It does not work.
I know this question may be too simple but I really do not know how to fix it.
I would appreciated if you could help me.
This is my code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Test extends Application{
Button button;
public static void main(String[] args){
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
stage.setTitle("Title");
StackPane layout = new StackPane();
button = new Button();
layout.getChildren().add(button);
Scene scene = new Scene(layout);
stage.setScene(scene);
stage.show();
}
}
and I got the error:
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 #0x46b3f4cf) 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 #0x46b3f4cf
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 Test.start(Test.java:21)
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.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application Test

From the error I'm assuming you're using JavaFX 11 (or at least JavaFX 9+). Note that the ultimate problem is not the InvocationTargetException but the IllegalAccessError:
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.scene.control.ControlHelper (in unnamed module #0x46b3f4cf) 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 #0x46b3f4cf
This is telling you code in the "unnamed module" is trying to access internals of the javafx.graphics module. As this is not allowed the error is thrown. But the real problem here is that ControlHelper is in the unnamed module but it's supposed to be in the javafx.controls module, if the package name is anything to go by. This problem is caused by having javafx.graphics on the modulepath but javafx.controls on the classpath.
Make sure you have both modules (and javafx.base) on the --module-path. As your code is not modular (no module-info file) you will also have to tell the module system to resolve it by using:
--add-modules javafx.controls
You don't have to include javafx.graphics in the --add-modules command because javafx.controls requires javafx.graphics (and javafx.graphics requires javafx.base). As all modules are on the modulepath they will be resolved.
How you set these commands is dependent on how you launch your application (e.g. command-line, IDE, Maven, Gradle, etc...).
If you ever make your code modular you won't need to use the --add-modules command, just put the appropriate requires directives in your module-info file. For example:
module app {
requires javafx.controls;
}

Related

Problem starting my application using JavaFX [duplicate]

This question already has answers here:
Module error when running JavaFx media application
(2 answers)
Closed 8 months ago.
So i'm using IntelliJ and I built my application using JavaFX.
But when i'm starting my main:
package fr.agglomistral.programme;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import fr.agglomistral.classedao.BusDAO;
import fr.agglomistral.classemetier.Bus;
import fr.agglomistral.outils.ConnexionMysql;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fr/agglomistral/vues/Login.fxml"));
primaryStage.setTitle("AggloMistral");
primaryStage.setScene(new Scene(root,1680,1020));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
BusDAO busDAO = new BusDAO();
Bus bus = new Bus("MARQUE", "IMMAT", 12, 12);
busDAO.create(bus);
ConnexionMysql.disconnect();
}
}
I get the following errors, and I don't get where those come from...
Everything was working perfectly until I switched branches on github and had to set all the configurations all over again...
This is a picture of my configuration below:
The errors I'm getting:
"C:\Program Files\Java\jdk-17.0.2\bin\java.exe" --module-path C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib --add-modules=javafx.controls "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.1\lib\idea_rt.jar=3220:C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\lilian.carion\Documents\Agglo-Mistral\classes\production\Agglo-Mistral;C:\Users\lilian.carion\Documents\mysql-connector-java-8.0.29\mysql-connector-java-8.0.29.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx-swt.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.web.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.base.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.fxml.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.media.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.swing.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.controls.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.graphics.jar;C:\Users\lilian.carion\Downloads\javafx\javafx-swt.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.web.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.base.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.fxml.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.media.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.swing.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.controls.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.graphics.jar;C:\Users\lilian.carion\Downloads\jsch-0.1.55.jar;C:\Users\lilian.carion\.m2\repository\junit\junit\4.13.1\junit-4.13.1.jar;C:\Users\lilian.carion\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.1\junit-jupiter-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.1\junit-jupiter-api-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\lilian.carion\.m2\repository\org\junit\platform\junit-platform-commons\1.8.1\junit-platform-commons-1.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.1\junit-jupiter-params-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.1\junit-jupiter-engine-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\junit\platform\junit-platform-engine\1.8.1\junit-platform-engine-1.8.1.jar fr.agglomistral.programme.Main
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:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x7dff628f) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x7dff628f
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2135)
at fr.agglomistral.programme.Main.start(Main.java:22)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#18.0.1/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#18.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Exception running application fr.agglomistral.programme.Main
Process finished with exit code 1
I had similar issue. For me solution was to
add following configuration :
--add-modules javafx.controls,javafx.fxml
insted of just
--add-modules javafx.controls

java program not running in intellij idea after i restart the intellij idea some internal call is showing up

Internal error (java.lang.reflect.InaccessibleObjectException): Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module #1b1473ab
java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module #1b1473ab
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at com.intellij.util.ReflectionUtil.makeAccessible(ReflectionUtil.java:253)
at com.intellij.util.ReflectionUtil.getDeclaredMethod(ReflectionUtil.java:270)
at com.intellij.DynamicBundle.(DynamicBundle.java:28)
at org.jetbrains.jps.incremental.scala.InitialScalaBuilder.getPresentableName(InitialScalaBuilder.scala:26)
at org.jetbrains.jps.incremental.IncProjectBuilder.lambda$sendElapsedTimeMessages$3(IncProjectBuilder.java:451)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.concurrent.ConcurrentHashMap$EntrySpliterator.forEachRemaining(ConcurrentHashMap.java:3652)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.jetbrains.jps.incremental.IncProjectBuilder.sendElapsedTimeMessages(IncProjectBuilder.java:454)
at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:425)
at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)enter image description here
If you are using IntelliJ Community version 2021.2 there might be some errors so I would recommend going back to the 2021.1 version.
These errors don't specifically look like an IDE error, but just in case I would recommend going back a version.

why FXMLLoader giving error when used to load a FXML file? [duplicate]

This question already has answers here:
Module error when running JavaFx media application
(2 answers)
Closed 2 years ago.
I was following a JavaFX tutorial and wrote the following code.
All the required header files are imported.
Main.java
public class Main extends Application {
#Override
public void start(Stage primaryStage){
try {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Random Number Generator");
primaryStage.show();
}catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Main.fxml (created using SceneBuilder)
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane minHeight="100.0" minWidth="100.0" prefHeight="300.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
<children>
<Button id="button_generateRandomNumber" layoutX="171.0" layoutY="212.0" mnemonicParsing="false" onAction="#generateRandom" text="Generate Random Number" textAlignment="CENTER" textFill="#1e4d0e" />
<Label fx:id="message" layoutX="112.0" layoutY="143.0" prefHeight="45.0" prefWidth="258.0" textAlignment="CENTER" />
</children>
</AnchorPane>
StackTrace
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:564)
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:564)
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:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x5d85fddd) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x5d85fddd
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at application.Main.start(Main.java:20)
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(AccessController.java:391)
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.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application application.Main
I have tried every combination with getResource("Main.fxml") including relative and absolute path in every way possible still I am getting the error.
code is 100% same as of that tutorial.
In order to javafx work, you need to either download and import javafx sdk to your project or specify dependency, if you are using build tool like Maven or Gradle.
Moreover you need to add required modules (in this case javafx's .jars) either by using module-info.java and specifying required modules there, or adding modules to VM arguments - https://openjfx.io/openjfx-docs/#install-javafx.
Bonus:
Note that javafx was present in JDK up to version 10. Since version 11, they removed it. That is why you need to import javafx somehow to your project.

Java IllegalAccessError can't run Application

I'm setting up my first program for a class and I'm stuck on why my program won't run trying to debug. What do I need to do to debug this error?
I've tried to add libraries but this didn't seem to work.
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.awt.*;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try{
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
primaryStage.setTitle("My First JavaFX GUI");
Button button= new Button("Submit Answer");
StackPane layout= new StackPane();
layout.getChildren().add(button);
Scene scene1= new Scene(layout, 300, 250);
primaryStage.setScene(scene1);
primaryStage.show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
This is the error my Run Console is giving me:
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: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x41b2844d) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x41b2844d
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at Main.start(Main.java:20)
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.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application Main
Process finished with exit code 1
I expect this to run, but it won't and I'm really stuck on where to act.
Thanks for taking a look ! Any help is appreciated :D
Add the modules to your modulepath. Most projects just need javafx.controls and javafx.fxml but check to see if you need other packages.
Run > Edit Configuration > VM Options >
--module-path /path/to/javafx-sdk-13/lib --add-modules javafx.controls,javafx.fxml
Like so:
Additionally make sure that your SDK and project language level is properly setup in:
File > Project Structure > Project
Make sure that your OpenFX library is added (either manually or with something like Gradle) in:
File > Project Structure > Libraries
And one last thing, I don't think you meant to import java.awt.*; in your code.

Cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) - JavaFX & Eclipse

I have follow this guide to setup JavaFX onto a Linux machine.
First I have installed Java 11
asus#asus-pc:/usr/share/openjfx/lib$ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu219.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu219.04.1, mixed
mode, sharing)
asus#asus-pc:/usr/share/openjfx/lib$
Then I have installed OpenJFX from the command sudo apt-get install openjfx
asus#asus-pc:/usr/share/openjfx/lib$ ls
javafx.base.jar javafx.graphics.jar javafx.swing.jar
javafx.controls.jar javafx.media.jar javafx.web.jar
javafx.fxml.jar javafx.properties src.zip
asus#asus-pc:/usr/share/openjfx/lib$
Then have created a library in Eclipse.
Then I have include it into my java project. I try to run this code:
package se.danielmartensson.start;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application{
/*
* Start the start(Stage front)
*/
public static void main(String[] args) {
launch();
}
#Override
public void start(Stage front) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/JUSBPlotter/src/se/danielmartensson/fxml/front.fxml"));
Scene scene = new Scene(root);
front.setScene(scene);
front.setTitle("Fracken");
front.show();
}
}
And I have change the run configurations to:
But when I compile the code. I get this errors:
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: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x1ff6d2c7) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x1ff6d2c7
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at se.danielmartensson.start.Main.start(Main.java:20)
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 se.danielmartensson.start.Main
Question:
Is there anyone where who know how to solve this error? I have setup JavaFX before, but this time, it won't work for me.
Edit 1:
If I change the run configurations to:
--module-path="/usr/share/openjfx/lib" --add-modules=javafx.controls,javafx.fxml
I get this errors
Having the same issue with IntelliJ IDEA 2020.1 with JDK 14.
Finally resolved by adding a module-info.java like this one under src/main/java if you use maven:
module sample {
requires javafx.controls;
requires javafx.graphics;
opens sample;
}
Go to Run>Run Configurations then Arguments tab and go to VM Arguments and paste the following code to add modules
"--module-path /path/to/lib --add-modules javafx.controls,javafx.fxml"
remember to modify /path/to/lib to your path your library
then click apply and you're set
thanks, works for me as follows
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
module-info.java:
module sample {
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
opens sample ;
}
Thank you igonejack. I did what you said but I faced some other exceptions after that, So I came up with below code:
module {pkg}{
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
exports {pkg of Application class};
opens {pkg};
}
after that you need to rebuild your project probably because of some exception about Kotlin.
Then I saw exception "location is not set". To solve this you must start fxml location with "/" such as:
App.class.getResource("/form.fxml");
Edit
I made a HelloWorld project at JavaFxHelloWorld using Gradle.
As marco-rosati proposed in #638 issue, if you are using maven you can simply add this plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine> --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED </argLine>
</configuration>
</plugin>

Categories

Resources