Issue
I have been endeavouring to implement a JavaFX application using FXML which includes a WebView.
However, when run this results in a ClassNotFoundException:javafx.scene.web.WebView leading to a javafx.fxml.LoadException, but I am perplexed by this.
Consequently, I have created a simplified application as follows. The Controller is empty in this example. If anybody can inform me how to successfully implement a WebView it will be much appreciated.
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("wv.fxml"));
primaryStage.setTitle("WebView Test");
primaryStage.setScene(new Scene(root, 500, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
wv.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.web.WebView?>
<FlowPane fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<WebView fx:id="WV" prefWidth="200" prefHeight="200"></WebView>
</FlowPane>
module-info.java
module WebViewTest {
requires javafx.fxml;
requires javafx.controls;
opens sample;
}
Solution
Have a look at your module-info and wonder why you don't have javafx.web in there.
Answered By - mipa