我在通过Gluon客户端插件运行GraalVM(基于JDK 11构建的最新GraalVM)产生的本机映像时遇到错误。
javafx.fxml.LoadException:解决onaction ='#loginaction'时出错,事件处理程序不在命名空间中或脚本中有错误。 fxml / LoginScreen.fxml:17
整理步骤可以正常工作:
mvn clean client:build
我在名为“ 项目名称 / target / client / x86_64-linux / 二进制名称”的文件夹中看到了二进制文件
当我通过“ ./ binaryname ”运行可执行文件时,产生了以上错误
第17行抱怨的FXML代码行是:
<Button fx:id="_loginButton" layoutX="516.0" layoutY="174.0" mnemonicParsing="false" onaction="#loginaction" prefHeight="28.0" prefWidth="94.0" text="Login" />
支持代码逻辑如下,并标记为@FXML:
@FXML
void loginaction(actionEvent event) throws InterruptedException {
LoginService loginservice = new LoginService(_usernameTextField.getText(),_passwordTextField.getText());
根据JavaFX的常见错误列表,该问题通常是因为onaction事件的名称与控制器中指定的名称不同-Introduction to JavaFX for Beginner Programmers - Pg 27 。但是事实并非如此,我的程序的命名是准确的。使用
使用JavaFX maven插件(与GluonClient分开)maven javafx:run
该程序正确启动并按预期运行。如果我需要发布更多信息,请告诉我。
这是我的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>com-demo-management-ui</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>
<client.plugin.version>0.1.26</client.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>com.demo.Launcher</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<version>${client.plugin.version}</version>
<configuration>
<!-- Uncomment to run on iOS: -->
<!-- <target>ios</target> -->
<mainClass>com.demo.Launcher</mainClass>
<graalvmHome>/opt/graalvm-ce-java11-20.2.0-dev/</graalvmHome>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>gluon-releases</id>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
</pluginRepository>
</pluginRepositories>
最后,这是我设置控制器的代码(这是一个方法调用,我根据需要交换视图,因此控制器在创建视图时作为参数传递):
FXMLLoader fxmlLoader = new FXMLLoader(getclass().getResource("/fxml/"+baseController.getFxmlFile()));
fxmlLoader.setController(baseController);
Parent parent = fxmlLoader.load();
Scene scene = new Scene(parent);
Stage stage = new Stage();
stage.setfullScreen(fullScreen);
stage.setMaximized(setMaximized);
stage.setScene(scene);
stage.show();