1

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;
}
Datango
  • 45
  • 4
  • 1
    please edit and add the complete stacktrace – kleopatra Oct 01 '21 at 11:39
  • Does this answer your question? [Module error when running JavaFx media application](https://stackoverflow.com/questions/53237287/module-error-when-running-javafx-media-application) – kleopatra Oct 01 '21 at 14:07

1 Answers1

4

Have a look at your module-info and wonder why you don't have javafx.web in there.

mipa
  • 10,369
  • 2
  • 16
  • 35