0

I am trying to run a JavaFX application on eclipse. Easy code like printing out hello world or entering a name are working. But when I am trying to run a modified fmxl-file I am getting different errors.

At first I got the message:

Error occurred during initialization of boot layer java.lang.module.FindException: Two versions of module jurt found in /usr/share/java (jurt-6.0.7.jar and jurt.jar)

But when deleting the versions which are double the errormessage changed to:

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 @0x65d71619) 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 @0x65d71619
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
    at application.Main.start(Main.java:17)
    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 application.Main

This is my main class:

package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
           //BorderPane root = new BorderPane();

            Parent root = FXMLLoader.load(getClass().getResource("/application/scene1.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

And this my fxml-file:

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

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="300.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.MainController">
  <!-- TODO Add Nodes -->
  <children>
    <Button layoutX="185.0" layoutY="140.0" mnemonicParsing="false" onAction="#generateRandom" text="Münzwurf" />
    <Label layoutX="14.0" layoutY="63.0" text="Kopf oder Zahl du hast die Wahl:" />
    <TextField layoutX="241.0" layoutY="60.0" prefWidth="200.0" text="Kopf oder Zahl ?" />
  </children>
</AnchorPane>

My class controller just create a random number which I want to be printed out.

I imported the libraries with external jars into my project.

I am running this on a ubuntu 18.4 maschine with jdk11, openjfx11 and jre1.8/11

My next step will be to try the code on jdk1.8 with openjfx8

Does anyone have a clue how to fix this ?

  • 2
    You need to use `javafx.fxml` from the modulepath. Try adding `--add-modules javafx.fxml` to your VM arguments. Also, you're getting a _runtime_ error, which means your code _compiled_ just fine. – Slaw Oct 28 '19 at 21:38
  • See the answer to [IntelliJ can't recognize JavaFX 11 with OpenJDK 11](https://stackoverflow.com/questions/52467561/intellij-cant-recognize-javafx-11-with-openjdk-11). You aren't using IntelliJ, but the concepts and issues are similar. – jewelsea Oct 28 '19 at 23:01
  • Got it running!! Thanks Slaw! I just had forgot to unzip the source folder in openjfx, so eclipse didnt found javafx.fxml. – Hadadadebadada Oct 29 '19 at 12:45
  • Possible duplicate of [How to add JavaFX runtime to Eclipse in Java 11?](https://stackoverflow.com/questions/52144931/how-to-add-javafx-runtime-to-eclipse-in-java-11) – smac89 Oct 30 '19 at 03:39

0 Answers0