0

when I try to get a WebPage with the class com.sun.javafx.webkit.Accessor, I always see the following exception:

Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class application.Main$1 (in unnamed module @0x22c53437) cannot access class com.sun.javafx.webkit.Accessor (in module javafx.web) because module javafx.web does not export com.sun.javafx.webkit to unnamed module @0x22c53437
    at application.Main$1.run(Main.java:144)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    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:184)
    at java.base/java.lang.Thread.run(Thread.java:833)

I found this article Cannot access JavaFX class "WebPage" in IntelliJ-IDEA but I don't know how to integrate this. I am using javafx sdk 17.0.1 and jdk-17 (JavaSE-1.8).

EDIT:

For example, this doesn't work:

WebView webView = new WebView();
webView.getEngine().loadContent("<html><bodx><p>test</p></body></html>");
WebPage page = Accessor.getPageFor(webView.getEngine());
System.out.println(page);

But now it says:

Exception in Application start method

I already tried to update to JavaSE-17 and to set the VM Argument:

--add-exports javafx.web/com.sun.webkit.dom=ALL-UNNAMED

and

--add-exports javafx.web/com.sun.webkit=ALL-UNNAMED

but nothing changed.

7
  • 1
    minimal reproducible example please.. Commented Feb 3, 2022 at 22:54
  • Does this answer your question? Package 'com.sun.webkit.dom' is declared in module 'javafx.web', which does not export it to module Commented Feb 3, 2022 at 23:41
  • JavaFX 17 has a minimum JRE requirement of 11, though I recommend JRE 17 and definitely not 8. Commented Feb 4, 2022 at 0:06
  • 1
    Direct app access to com.sun classes is generally not recommended as they are not public API. Though I guess it is something to try if you have no other alternative, just be aware that such access is not supported by the framework developers and may break without notice in future platform releases. Ignore this comment if you are not directly using the com.sun classes. Commented Feb 4, 2022 at 0:08
  • Though you say you are using JDK 8, that doesn't look like a stack trace that would be generated by JDK 8. Commented Feb 4, 2022 at 2:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.