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.

CPU
  • 46
  • 4
  • 1
    [mcve] please.. – kleopatra Feb 03 '22 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](https://stackoverflow.com/questions/47684470/package-com-sun-webkit-dom-is-declared-in-module-javafx-web-which-does-not) – trashgod Feb 03 '22 at 23:41
  • JavaFX 17 has a minimum JRE requirement of 11, though I recommend JRE 17 and definitely not 8. – jewelsea Feb 04 '22 at 00:06
  • 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. – jewelsea Feb 04 '22 at 00:08
  • Though you say you are using JDK 8, that doesn't look like a stack trace that would be generated by JDK 8. – jewelsea Feb 04 '22 at 02:22
  • Try the steps outlined in: [can not resolve symbol "javafx.scene.web"](https://stackoverflow.com/a/70946444/1155209), which suggests creating a new project in Idea and adding a dependency for the javafx.web module, using JDK 17.0.2 and JavaFX 17.0.2. – jewelsea Feb 04 '22 at 02:26
  • I mean jdk 17 (JavaSE-1.8) – CPU Feb 04 '22 at 18:15

0 Answers0