I am trying to start a javafx window and whenever I run it, I get java.lang.reflect.InaccessibleObjectException: Unable to make field private javafx.scene.web.WebView com.vendify.FX.FXMLDocumentController.webView accessible: module com.vendify.FX does not "opens com.vendify.FX" to module javafx.fxml
Currently, my setup looks like this:
App.java
package com.vendify.FX; import java.io.File; import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; /** * JavaFX App */ public class App extends Application { @Override public void start(Stage stage) throws IOException { File webViewFXML = new File("src/main/java/com/vendify/FX/test.fxml"); FXMLLoader loader = new FXMLLoader(webViewFXML.toURI().toURL()); Parent root = loader.load(); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } test.fxml
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> <?import javafx.scene.layout.Pane?> <?import javafx.scene.web.WebView?> <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.vendify.FX.FXMLDocumentController"> <children> <WebView fx:id="webView" layoutX="-1.0" layoutY="61.0" prefHeight="339.0" prefWidth="600.0"/> </children> </Pane> FXMLDocumentController.java
package com.vendify.FX; import java.net.URL; import java.util.ResourceBundle; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.web.WebView; public class FXMLDocumentController implements Initializable { @FXML private WebView webView; @Override public void initialize(URL url, ResourceBundle rb) { System.out.print("\n\n\n\n\n\ninitialize called\n\n\n\n"); // WebEngine engine = webView.getEngine(); // engine.load("http://www.newgrounds.com/"); } public void reloadPage() { System.out.print("buttonClicked"); } } module-info.java
module com.vendify.FX { requires javafx.controls; requires javafx.fxml; requires javafx.web; exports com.vendify.FX; }
and lastly, pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.vendify</groupId> <artifactId>FX</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>16</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>16</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> <version>16</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-web</artifactId> <version>16</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>11</release> <argLine> --illegal-access=permit </argLine> </configuration> </plugin> <plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.6</version> <executions> <execution> <!-- Default configuration for running --> <!-- Usage: mvn clean javafx:run --> <id>default-cli</id> <configuration> <mainClass>com.vendify.FX.App</mainClass> <argLine> --illegal-access=permit </argLine> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> I am running on jdk 14 (which is above the jdk 11 requirement), and I'm really quite stuck. In my .fxml, If I remove fx:controller="com.vendify.FX.FXMLDocumentController", it seems to run fine, but does not properly call Initialize(), and thus, the webView does not actually load a page.
I am kind of new to this javaFX, so any help is greatly appreciated!
opens com.vendify.FX to javafx.fxml;directive to your module-info descriptor.