gpt4 book ai didi

java - 这个fxml错误代码在JavaFx中意味着什么

转载 作者:行者123 更新时间:2023-12-02 09:15:22 25 4
gpt4 key购买 nike

这是我不断收到的错误代码:

 Nov 26, 2019 12:33:25 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX runtime of version 8.0.221
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: Error resolving onAction='#handlebuttonAction', either the event handler is not in the Namespace or there is an error in the script.
/D:/Eclipse%20Java/Workspace/EmployeeApp1/bin/application/Directory.fxml:83

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at application.Main.showMainView(Main.java:27)
at application.Main.start(Main.java:20)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
... 1 more
Exception running application application.Main

我的教授告诉我这可能是我的应用程序的命名,我检查了一下,命名应该位于应用程序文件的正下方。这是我的程序的文件设置:

setup

以下是我一直用来尝试通过运行 main.java 文件来显示此内容的代码:

Scenebuilder

Main.java

package application;

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;



public class Main extends Application {
@FXML private Stage primaryStage;
@FXML private BorderPane borderPane;
@Override
public void start(Stage primaryStage) throws IOException{
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Assignment 5: by ");
showMainView();

}

private void showMainView() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("Directory.fxml"));
borderPane = loader.load();
Scene scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}


public static void main(String[] args) {
launch(args);
}
}

目录.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<TitledPane text="Assignment 5-Kevin Yuan" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.DirectoryController">
<content>
<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="320.0">
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" />
</padding>
<center>
<BorderPane BorderPane.alignment="CENTER">
<right>
<GridPane BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="62.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="245.0" minWidth="10.0" prefWidth="245.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Name:" textAlignment="CENTER">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Company:" textAlignment="CENTER" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="50.0" prefWidth="94.0" text="Extension:" textAlignment="RIGHT" GridPane.rowIndex="2">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<TextField fx:id="txtFldName" disable="true" promptText="First Last" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="txtFldCompany" disable="true" layoutX="89.0" layoutY="85.0" onKeyPressed="#btnLoad" promptText="department name" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="txtFldExt" disable="true" layoutX="94.0" layoutY="15.0" onKeyPressed="#btnLoad" promptText="Ext. number" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<HBox alignment="BOTTOM_RIGHT" GridPane.columnIndex="1" GridPane.rowIndex="3">
<children>
<Label fx:id="lblCurrRecord" alignment="CENTER" contentDisplay="CENTER" maxHeight="25.0" maxWidth="1.7976931348623157E308" minHeight="25.0" prefHeight="25.0" prefWidth="150.0" text="? of ?" textAlignment="CENTER">
<font>
<Font name="System Bold Italic" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="5.0" />
</HBox.margin>
</Label>
<Button fx:id="btnNavDel" alignment="CENTER" contentDisplay="RIGHT" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#reactToClick" prefWidth="35.0" text="-">
<font>
<Font name="SansSerif Bold" size="12.0" />
</font>
<opaqueInsets>
<Insets left="20.0" />
</opaqueInsets>
<HBox.margin>
<Insets bottom="5.0" />
</HBox.margin>
</Button>
<Button fx:id="btnNavAdd" Visible="false" alignment="CENTER" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#reactToClick" prefWidth="35.0" text="+">
<font>
<Font name="SansSerif Bold" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox alignment="BOTTOM_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="4">
<children>
<Button fx:id="btnNavPrev" alignment="CENTER" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#reactToClick" prefWidth="35.0" text="&lt;&lt;">
<font>
<Font name="SansSerif Bold" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="5.0" />
</HBox.margin>
</Button>
<Button fx:id="btnNavNext" alignment="CENTER" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#reactToClick" prefWidth="35.0" text="&gt;&gt;">
<font>
<Font name="SansSerif Bold" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</GridPane>
</right>
</BorderPane>
</center>
<bottom>
<BorderPane BorderPane.alignment="CENTER">
<right>
<HBox BorderPane.alignment="CENTER">
<children>
<Button fx:id="btnLoad" alignment="TOP_RIGHT" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#reactToClick" text="Load" textAlignment="RIGHT">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
<Button fx:id="btnSerialize" alignment="CENTER" disable="true" mnemonicParsing="false" onAction="#handlebuttonAction" text="Serialize" textAlignment="RIGHT">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</right>
<center>
<Label fx:id="lblFilename" maxHeight="25.0" maxWidth="1.7976931348623157E308" text="File: not set" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</bottom>
<top>
<Button fx:id="btnExit" alignment="CENTER" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#Save" onMouseReleased="#Exit" prefWidth="92.0" style="" text="Save and Exit" textAlignment="CENTER" BorderPane.alignment="TOP_RIGHT">
<font>
<Font name="System Bold" size="12.0" />
</font>
<BorderPane.margin>
<Insets bottom="10.0" top="5.0" />
</BorderPane.margin>
</Button>
</top>
</BorderPane>
</content>
</TitledPane>

最佳答案

Caused by: javafx.fxml.LoadException: Error resolving onAction='#handlebuttonAction', either the event handler is not in the Namespace or there is an error in the script.
/D:/Eclipse%20Java/Workspace/EmployeeApp1/bin/application/Directory.fxml:83

阅读上面的错误消息:事件处理程序不在命名空间中,或者脚本中存在错误。,意味着您正在调用不存在的按钮按下方法。检查以下 FXML 代码行:

<Button fx:id="btnExit" alignment="CENTER" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#Save" onMouseReleased="#Exit" prefWidth="92.0" style="" text="Save and Exit" textAlignment="CENTER" BorderPane.alignment="TOP_RIGHT">

一个可能的解决方案:您可以从 FXML 代码中删除此 onAction="#handlebuttonAction"。 (我上面提到的那一行。)

关于java - 这个fxml错误代码在JavaFx中意味着什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59044444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com