我正在为我的 lan 应用程序创建包含日志的表。当我尝试运行此应用程序时,它会抛出 NullPointerException,但 fx:id 和 fx:controller 是正确的。我正在使用 JavaFX 12。
我尝试使用 Intellij 重构 fx:id 和 fx:controller,Intellij 也在 logPane.fxml 和 LogPaneController.class 中正确地更改了它,但它仍然无法正常工作。如果我注释掉异常所在的行,则所有应用程序都可以正常工作。我用谷歌搜索短语“FXML 组件返回 NUllPointerException”,但结果始终是“您的 fx:id 或 fx:controller 名称在控制器中不相同”。
日志面板.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane HBox.hgrow="ALWAYS" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.lanssmaker.controller.LogPaneController">
<children>
<TableView fx:id="logTable" prefHeight="574.0" prefWidth="382.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn maxWidth="140.0" minWidth="70" prefWidth="70.0" text="Time"/>
<TableColumn text="Content"/>
<TableColumn maxWidth="140.0" minWidth="70" prefWidth="70.0" text="Category"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
LogPaneController.class
public class LogPaneController {
@FXML
private TableView<Log> logTable; //it's null
public TableView<Log> getLogTableView() {
return logTable;
}
public void initialize() {
//example ussage calling NullPointerException
logTable.isHover();
}
}
慕工程0101907
子衿沉夜
30秒到达战场
随时随地看视频慕课网APP
相关分类