我正在創(chuàng)建一個(gè) JavaFX 應(yīng)用程序。我可以啟動(dòng)應(yīng)用程序并登錄,但是當(dāng)我嘗試訪問客戶場(chǎng)景時(shí),出現(xiàn)以下錯(cuò)誤:(提前對(duì)所有代碼和錯(cuò)誤表示歉意;不想遺漏任何內(nèi)容)這是 CustomersScene.fxml:<?xml version="1.0" encoding="UTF-8"?><?import javafx.scene.control.Button?><?import javafx.scene.control.Label?><?import javafx.scene.control.TableColumn?><?import javafx.scene.control.TableView?><?import javafx.scene.layout.AnchorPane?><?import javafx.scene.layout.HBox?><?import javafx.scene.layout.VBox?><?import javafx.scene.text.Font?><AnchorPane id="AnchorPane" prefHeight="591.0" prefWidth="475.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="c195.CustomersSceneController"> <children> <VBox layoutY="51.0" prefHeight="541.0" prefWidth="500.0"> <children> <TableView fx:id="customerTableView" prefHeight="470.0" prefWidth="500.0"> <columns> <TableColumn fx:id="customerTableNameTableColumn" prefWidth="75.0" text="Name" /> <TableColumn fx:id="customerTableAddressTableColumn" prefWidth="302.0" text="Address" /> <TableColumn fx:id="customerTablePhoneNumberTableColumn" minWidth="0.0" prefWidth="122.0" text="Phone Number" /> </columns> </TableView> <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="100.0"> <children> <Button fx:id="addCustomerButton" mnemonicParsing="false" onAction="#addCustomerButtonPushed" prefHeight="30.0" prefWidth="60.0" text="Add" /> <Button fx:id="modifyCustomerButton" mnemonicParsing="false" onAction="#modifyCustomerButtonPushed" prefHeight="30.0" prefWidth="60.0" text="Modify" /> <Button fx:id="deleteCustomerButton" mnemonicParsing="false" onAction="#deleteCustomerButtonPushed" prefHeight="30.0" prefWidth="60.0" text="Delete" /> </children>該錯(cuò)誤表明它找不到事件處理程序。我不知道為什么,因?yàn)槲乙褜?@FXML 附加到該函數(shù)。我還嘗試將函數(shù)公開(fxml 文檔仍然建議這兩個(gè)函數(shù),該文檔在第 27 行顯示錯(cuò)誤 - > #deleteCustomerButtonPushed) 我已檢查所有導(dǎo)入語句以確保使用 JavaFX 版本。
3 回答

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
您收到的 IncationTargetException 意味著系統(tǒng)正在嘗試查找特定方法,但無法找到合適的候選方法。正如錯(cuò)誤所示:“事件處理程序不在命名空間中”。
問題來自于你的方法的簽名:
@FXML private void deleteCustomerButtonPushed(Customer customer) {
//...
}
參數(shù)應(yīng)該像ActionEvent其他方法一樣,而不是Customer.
@FXML private void deleteCustomerButtonPushed(ActionEvent e) {
//...
}

眼眸繁星
TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊
也可能是由于
使用
import java.awt.event.ActionEvent;
代替
import javafx.event.ActionEvent;

叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
我收到此錯(cuò)誤的原因是我錯(cuò)過了@FXML
方法聲明
是這樣的
private void onCheckboxToggle(ActionEvent event) {
添加了@FXML
@FXML private void onCheckboxToggle(ActionEvent event) {
我的自定義組件(沒什么特別的):
<CheckBox fx:id="completed" onAction="#onCheckboxToggle" />
添加回答
舉報(bào)
0/150
提交
取消