Невозможно запустить JAVAFX start
Я пытаюсь запустить окно javafx, и всякий раз, когда я его запускаю, получаю
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
В настоящее время моя установка выглядит так:
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;
}
и, наконец, 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>
Я работаю на jdk 14 (что выше требований jdk 11), и я действительно застрял. В моем .fxml, если я удалю
fx:controller="com.vendify.FX.FXMLDocumentController"
, похоже, он работает нормально, но не вызывает должным образом Initialize (), и поэтому webView фактически не загружает страницу.
Я новичок в этом javaFX, поэтому приветствую любую помощь!