C
C
chelovek_rediska2019-05-22 21:56:39
linux
chelovek_rediska, 2019-05-22 21:56:39

How to fix error when using JavaFX in Java11?

I use maven , javafx and java11 in the project . I connect all dependencies for JavaFX, classes see all imports. I run the project and the following error is thrown:

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

Swears at a line in the Main class
Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml"));

5ce59a9ce5c3d904604193.png
pom.xml
...
<dependencies>
        ...
 
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>11.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>11.0.2</version>
        </dependency>

    </dependencies>
...
         <plugins>
          <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.2</version>
                <configuration>
                    <mainClass>Main</mainClass>
                </configuration>
            </plugin>
        </plugins>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
O. J, 2019-05-23
@chelovek_rediska

Prior to javafx 11, all called javafx modules were available from the sdk by default, since version 11 you must connect the modules yourself.
it says that in the javafx.graphics module there is a call to the com.sun.javafx.util module, but it cannot be accessed because the desired module is not exported to the project.
just include the com.sun.javafx.util library in your project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question