Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

FXMLLoader.load throws java.lang.IllegalAccessError #548

Open
JagarYousef opened this issue Aug 1, 2019 · 9 comments
Open

FXMLLoader.load throws java.lang.IllegalAccessError #548

JagarYousef opened this issue Aug 1, 2019 · 9 comments

Comments

@JagarYousef
Copy link

JagarYousef commented Aug 1, 2019

I am using Intellij (JavaFX with Maven module), after adding the javafx plugins I get the following 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:567)
	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:567)
	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:835)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x36cbb069) 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 @0x36cbb069
	at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
	at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
	at app.Main.start(Main.java:24)
	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:389)
	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 app.Main

it is happening on:
Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml")); // The sample.fxml is in the resources folder
Here is my maven pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>Pere</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>12.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>12.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>12.0.2</version>
        </dependency>
    </dependencies>



</project>
@kevinrushforth
Copy link
Collaborator

The following is suspicious:

Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x36cbb069) 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 @0x36cbb069

The FXMLLoaderHelper class should be coming from the javafx.fxml module not the unnamed module.

@jperedadnr or @abhinayagarwal might be able to comment on this.

@nlisker nlisker changed the title java.lang.IllegalAccessError FXMLLoader.load throws java.lang.IllegalAccessError Aug 2, 2019
@abhinayagarwal
Copy link
Contributor

abhinayagarwal commented Aug 2, 2019

The issue here is with how IntelliJ IDEA handles a Java application with JavaFX dependencies. The following java command is executed by IntelliJ IDEA when a JavaFX 11+ application with OP's pom.xml is executed:

java --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED ... -p ~/.m2/repository/org/openjfx/javafx-base/12.0.2/javafx-base-12.0.2-linux.jar:~/.m2/repository/org/openjfx/javafx-graphics/12.0.2/javafx-graphics-12.0.2-linux.jar org.openjfx.App

It adds javafx.base and javafx.graphics to the module-path and leaves out javafx.controls and javafx.fxml on the classpath, causing all the confusion.

Solutions

  1. Add the missing modules manually to the module-path. Check this SO answer from @jperedadnr
  2. Run javafx:run goal from IntelliJ Maven window instead of running the Application class

@Gwulior
Copy link

Gwulior commented Mar 27, 2020

Also faced this issue.
Should we create a bug on Idea bugtracker?

@WEshalom
Copy link

I think we should

@WEshalom
Copy link

Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class checkersFX.Main (in module CheckersFX) because module CheckersFX does not export checkersFX to module javafx.graphics
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)

@kevinrushforth
Copy link
Collaborator

Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class checkersFX.Main (in module CheckersFX) because module CheckersFX does not export checkersFX to module javafx.graphics

This is not the same issue discussed above. It is an application error. See https://openjfx.io/javadoc/14/javafx.graphics/javafx/application/Application.html and look for "Deploying an Application as a Module".

@WEshalom
Copy link

Thank you

@Unays7
Copy link

Unays7 commented Dec 27, 2020

Caused by: java.lang.IllegalAccessException: class javafx.fxml.FXMLLoader$ValueElement (in module javafx.fxml) cannot access class UXUI.MainMenuController (in module src) because module src does not export UXUI to module javafx.fxml

Really not sure what's going on here, any help appreciated!

@Er4g00n
Copy link

Er4g00n commented Jan 18, 2021

Hey ! I fixed this problem by adding the configuration parameters :
--module-path "your path\javafx-sdk-15.0.1\lib" --add-modules=javafx.controls,javafx.fxml

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants