HTMLEditor JavaFX

Tintenfisch

Bekanntes Mitglied
Hallo,
folgendes Problem: Ich möchte an sich nur den enthaltenen HTMLEditor einbinden, aber mehr erhalte nur lauter Fahler.
Folgend mal der Code, sowie die Fehlermeldung. Über Hilfe wäre ich sehr dankbar =)

Java:
package application;
    
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.web.HTMLEditor;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            VBox root = new VBox();
            
            HTMLEditor editor = new HTMLEditor();
            root.getChildren().add(editor);
            
            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);
    }
}


Fehlermeldung:
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 javafx.scene.web.HTMLEditor (in unnamed module @0x2b916738) cannot access class com.sun.javafx.scene.control.ControlHelper (in module javafx.controls) because module javafx.controls does not export com.sun.javafx.scene.control to unnamed module @0x2b916738
at javafx.scene.web.HTMLEditor.<init>(HTMLEditor.java:50)
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(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
 
Also ich würde erst einmal dazu raten, nicht mit den unnamed module zu arbeiten. Das führt schnell zu Problemen, da z.B. der FXMLLoader per deep reflection Deine Klasse verarbeiten möchte und dazu braucht es eine opens Anweisung in der module-info.

Ob das jetzt diesen Fehler auch behebt, kann ich im Augenblick nicht sagen. Ich bin bei der Suche eben teilweise über ähnliches gestolpert wo das mit eine Lösung gewesen sein soll...

Generell auch die Frage: Wie arbeitest Du derzeit mit JavaFX? Wie nutzt Du es? Arbeitest Du mit Gradle oder Maven?
 
Okay, danke schon einmal für die Antwort.
Ich habe eben mal ein wenig gelesen, muss aber dennoch fragen: Wie "benenne" ich das Modul denn? Ich denke mal, bei der Erstellung des Projekts, aber das war es dann auch schon.
Bezüglich Gradle oder Maven, würde ich jetzt mal nach kurzer Recherche auf Maven tippen. Aber ehrlich gesagt, habe ich die beiden Begriffe zwar schonmal gehört, standen aber bisher noch nicht zum Thema. Arbeiten tue ich mit Eclipse, wo zuerst nur die Libary unter java Build Path > Classpath adde. Danach kommt der Code.
 
Du erstellst direkt im Hauptverzeichnis der Sourcen eine module-info.java

Da kommt dann etwas rein wie:
Java:
module modulname.de.du.dir.ausdenkst.main {
    requires javafx.controls;
    requires javafx.fxml;
    
    exports namespace1;
    opens namespace1;
    
    exports namespace2;
    opens namespace2;   
}

So in der Art ... Bei dir wäre das Minimum etwas wie:

Java:
test.main {
    requires javafx.controls;
    requires javafx.fxml;
    
    exports application;
    opens application;
}
 

Zurück
Oben