Skip to content
Advertisement

JavaFX Maven Exception in Application start method

So I’ve been stuck with this problem for a few days now. I found and read a lot of posts here on stackoverflow and other sites, but none of the solutions worked for me. I have a problem with my JavaFX in my maven project. I use java 15 and JavaFX 15.0.1. Here are files that I have in my project: The pom.xml 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>org.example</groupId>
    <artifactId>Maven_javaFx</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>15.0.1</version>
        </dependency>
    </dependencies>


</project>

Here is my Main.java class:

package main;

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 {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("src/main/java/resources/mainH/view.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Here is the view.fxml file:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.controller">
   <children>
      <Pane layoutX="200.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0">
         <children>
            <Button layoutX="74.0" layoutY="100.0" mnemonicParsing="false" text="Button" />
         </children>
      </Pane>
   </children>
</AnchorPane>

Here is the message that pops out when I try to compile my code:

C:Usersrafal.jdksopenjdk-15binjava.exe --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2020.2.3libidea_rt.jar=64406:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2020.2.3bin" -Dfile.encoding=UTF-8 -classpath C:UsersrafalDesktopstudiaRóżneMaven_javaFxtargetclasses;C:Usersrafal.m2repositoryorgopenjfxjavafx-controls15.0.1javafx-controls-15.0.1.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-controls15.0.1javafx-controls-15.0.1-win.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-graphics15.0.1javafx-graphics-15.0.1.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-graphics15.0.1javafx-graphics-15.0.1-win.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-base15.0.1javafx-base-15.0.1.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-base15.0.1javafx-base-15.0.1-win.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-fxml15.0.1javafx-fxml-15.0.1.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-fxml15.0.1javafx-fxml-15.0.1-win.jar -p C:Usersrafal.m2repositoryorgopenjfxjavafx-base15.0.1javafx-base-15.0.1-win.jar;C:Usersrafal.m2repositoryorgopenjfxjavafx-graphics15.0.1javafx-graphics-15.0.1-win.jar main.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:64)
    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:64)
    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:1071)
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 @0x5d7c5b47) 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 @0x5d7c5b47
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2138)
    at main.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(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 main.Main

Most post that I saw with that issue were resolved by changing the directory in getResource() method.I tried that and many other solutions as you can probably see in pom file. I ask you for help in resolving this problem as I have no more ideas on what to do. Any help will be appreciated. Thank you for helping in advance.

Advertisement

Answer

Thanks to a comment from @JoséPereda I found the solution to my problem. The issue was missing JavaFX Maven plugin and missing VM arguments.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement