FXML 中的 IOEXCEPTION 错误一次又一次。试图将 FXML 文件放在 ListView 中的列表元素上
IOEXCEPTION error again and again in FXML . Trying to put FXML file on a list element in ListView
public class PopupController {
public ListView<String> listView;
public Button addWalletButton;
public PieChart piechart;
public Label size;
private WalletModel walletModel = Factory.inject(WalletModel.class);
@FXML
public void initialize() throws IOException {
listView.setCellFactory(param -> new EditableCell());
addWalletButton.setOnMouseClicked(event -> {
walletModel.CreateWallet();
listView.getFixedCellSize();
listView.getItems().add("Wallet " + walletModel.WalletSize());
size.setText("Total Wallets: " + walletModel.WalletSize());
});
size.setText("Wallet Size " + walletModel.WalletSize());
listView.getItems().add("Wallet 1");
}
private class EditableCell extends ListCell<String>{
private final TextField textField;
EditableCell() throws IOException {
textField = new TextField();
setGraphic(FXMLLoader.load(getClass().getResource("/selectbutton.fxml")));
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if(empty){
textField.setVisible(false);
}
else{
textField.setVisible(true);
textField.setText(item);
}
}
}
}
它在 initialize() 方法的第一条语句中显示错误。
我正在尝试通过按钮 ("add wallet") 将 fxml
文件放在列表元素上。我在下面附上了我的 fxml
代码。
我没有收到堆栈跟踪,因为它显示编译错误
<AnchorPane prefHeight="27.0" prefWidth="69.0" xmlns="http://javafx.com/javafx/8.0.121"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gazman.coco.desktop.controllers.PopupController">
<Button fx:id="select" layoutX="6.0" layoutY="2.0" mnemonicParsing="false" text="Button"/>
</AnchorPane>
IOException
是一个已检查的异常,这意味着它必须以两种方式之一明确处理:
- 陷入
try-catch
语句的 catch
子句中
- 通过可能发生异常的方法传播。这是通过将
throws IOException
添加到方法签名的末尾来完成的。
这是为了强制开发人员在合理预期外部故障的情况下处理 IO 和其他操作的典型故障。
public class PopupController {
public ListView<String> listView;
public Button addWalletButton;
public PieChart piechart;
public Label size;
private WalletModel walletModel = Factory.inject(WalletModel.class);
@FXML
public void initialize() throws IOException {
listView.setCellFactory(param -> new EditableCell());
addWalletButton.setOnMouseClicked(event -> {
walletModel.CreateWallet();
listView.getFixedCellSize();
listView.getItems().add("Wallet " + walletModel.WalletSize());
size.setText("Total Wallets: " + walletModel.WalletSize());
});
size.setText("Wallet Size " + walletModel.WalletSize());
listView.getItems().add("Wallet 1");
}
private class EditableCell extends ListCell<String>{
private final TextField textField;
EditableCell() throws IOException {
textField = new TextField();
setGraphic(FXMLLoader.load(getClass().getResource("/selectbutton.fxml")));
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if(empty){
textField.setVisible(false);
}
else{
textField.setVisible(true);
textField.setText(item);
}
}
}
}
它在 initialize() 方法的第一条语句中显示错误。
我正在尝试通过按钮 ("add wallet") 将 fxml
文件放在列表元素上。我在下面附上了我的 fxml
代码。
我没有收到堆栈跟踪,因为它显示编译错误
<AnchorPane prefHeight="27.0" prefWidth="69.0" xmlns="http://javafx.com/javafx/8.0.121"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gazman.coco.desktop.controllers.PopupController">
<Button fx:id="select" layoutX="6.0" layoutY="2.0" mnemonicParsing="false" text="Button"/>
</AnchorPane>
IOException
是一个已检查的异常,这意味着它必须以两种方式之一明确处理:
- 陷入
try-catch
语句的catch
子句中 - 通过可能发生异常的方法传播。这是通过将
throws IOException
添加到方法签名的末尾来完成的。
这是为了强制开发人员在合理预期外部故障的情况下处理 IO 和其他操作的典型故障。