简体   繁体   中英

HTMLEditor causes Invocation Target Exception despite modified VM Options working with other JavaFX programs

I have used JavaFX and IntelliJ together before and I am usually able to get it to work. Now I am trying to use HTMLEditor, and despite giving IntelliJ the path to my JavaFX library directory and adding the same instructions I always do to my vm options for the "MyHTMLEditor" class, I still keep getting an Invocation Target Exception.

I have successfully run JavaFX with the same settings on other programs, so I feel like there's probably some module I need to add to the vm options to get HTMLEditor working, but I don't know what.

How can I stop my HTMLEditor object from generating an error?

I am using OpenJFX 12, and Oracle Java 12.

vm options instructions:

--module-path /home/myName/Java_Libraries/javafx-sdk-12.0.1/lib --add-modules=javafx.controls,javafx.fxml

the program:

public class MyHTMLEditor extends Application {

@Override
public void start(Stage stage) {

   stage.setTitle("My HTMLEditor");

   stage.setWidth(650650);
   stage.setHeight(300);

   final HTMLEditor htmlEditor = new HTMLEditor();
   htmlEditor.setPrefHeight(245);

   Scene scene = new Scene(htmlEditor);
   stage.setScene(scene);

   stage.show();
}

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

The 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 javafx.scene.web.HTMLEditor (in unnamed module @0x1858dacf) 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 @0x1858dacf
    at javafx.scene.web.HTMLEditor.<init>(HTMLEditor.java:50)
    at controllers.MyHTMLEditor.start(MyHTMLEditor.java:15)
    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.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 controllers.MyHTMLEditor

I just needed to add ",javafx.web" to the end of the VM Options instructions.

It's important that there is no space between the comma and "javafx.web".

So, the VM Options instructions become:

--module-path /home/myName/Java_Libraries/javafx-sdk-12.0.1/lib --add-modules=javafx.controls,javafx.fxml,javafx.web

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM