Reputation: 53
I am using Eclipse (javafx) and Scene Builder developing an app and I need to use a webview. My program is working smoothly, but when I add a webview component into an anchor pane, I got this error.
Caused by: java.lang.ClassNotFoundException: javafx.scene.web.WebView
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2931)
at javafx.fxml/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2920)
at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2861)
... 16 more
Exception running application view.Main
I tried to use the initialize function but still getting same errors, Can anyone tell me why? Thanks in advance.
Upvotes: 4
Views: 4156
Reputation: 405
In Gradle, make sure to add javafx.web
in the modules
list under JavaFX. Example below.
javafx {
version = '17.0.6'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
}
Then, for module-info.java
, make sure to add requires javafx.web;
.
Upvotes: 1
Reputation: 134
After i had this exact same error for a longtime, i solved adding the following arguments on eclipse>run>run configurations... then select the "Arguments" tab and add the text bellow to the "VM Arguments"
--module-path "%PHYSICAL_PATH_TO_JAVAFX%\lib" --add-modules javafx.controls,javafx.fxml,javafx.web
The main problem was that everywhere you go, they tell you to add the controls and fxml modules, but they never say that you may need to add more modules to those arguments. so i added the "javafx.web" and it solved my problem.
Upvotes: 10