【发布时间】:2018-03-31 00:25:13
【问题描述】:
每次用户尝试从 ListView 中删除项目时,我都会尝试添加确认类型的警报窗口。但是每当我这样做时,一旦我按下按钮,就会抛出一个 IllegalArgumentException 说,添加重复的孩子。代码如下:
@FXML
private void handleDeleteCaption() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Delete Caption");
alert.setHeaderText("Are you sure you want to delete this caption?");
alert.setContentText("All its contents will be lost. Continue?");
alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.CANCEL);
Optional<ButtonType> result = alert.showAndWait();
if(result.isPresent() && result.get() == ButtonType.YES) {
captionsList.getItems().remove(selectedCaption);
}
}
当我添加类型警告的警报时,也是同样的问题。它仅在我未指定警报类型时才有效,即当我将其声明为 AlertType.NONE 时。 我在这里的缺失点是什么?
【问题讨论】:
-
您是否在此方法的第一行或单击确定时收到 IllegalArgumentException?
-
@thurst0n 我在调用 showAndWait() 方法的那一行得到它
标签: java javafx alert illegalargumentexception