按下 javafx 按钮时不执行

No execution when javafx button pressed

我遇到的问题是,当我点击我的登录按钮时,它没有任何反应。没有抛出异常,try - catch 似乎没有捕获任何 errors/exceptions。一直在浏览线程,但没有找到任何有效的方法。

我在整个代码中添加了 print 语句,它似乎在第一个 try 块的开头就停止了,还在两个 catch 块中添加了一个 stackTrace 并且什么都没有

void getLoginAction(ActionEvent event) throws IOException, Exception {
        String username = tfUsername.getText();
        String password = tfPassword.getText();
        loggingUsers.setUserName(username);
        loggingUsers.setPassword(password);

        FileHandler userFh = new FileHandler("UserLog.txt", true);
        SimpleFormatter sf = new SimpleFormatter();
        userFh.setFormatter(sf);
        uLog.addHandler(userFh);
        uLog.setLevel(Level.INFO);

        try {
            ObservableList<User> loginInfo = DatabaseMan.getActiveUsers();

            loginInfo.forEach((u) -> {
                try {
                    assert loggingUsers.getUserName().equals(u.getUserName()) && loggingUsers.getPassword().equals(u.getPassword()) : "Incorrect login info!";
                    loggingUsers.setUserId(u.getUserId());
                    try {
                        Appointment upcomingAppt = DatabaseAppointments.getUpcomingAppt();
                        if (!(upcomingAppt.getAppointmentId() == 0)) {
                            Alert apptAlert = new Alert(Alert.AlertType.INFORMATION);
                            apptAlert.setTitle("Upcoming Appointment Reminder");
                            apptAlert.setHeaderText("You have an upcoming appointment!");
                            apptAlert.setContentText("You have an appointment scheduled" 
                                    + "\non " + upcomingAppt.getStart().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))
                                    + "\nat " + upcomingAppt.getStart().format(DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL))
                                    + " with client " + upcomingAppt.getCustomer().getCustomerName() + ".");
                            apptAlert.showAndWait();
                            if (apptAlert.getResult() == ButtonType.OK) {
                                userLog.log(Level.INFO, "User: {0} logged in.", loggingUsers.getUserName());
                                Stage loginStage = (Stage) btnLogin.getScene().getWindow();
                                loginStage.close();
                                FXMLLoader apptCalLoader = new FXMLLoader(AppointmentCalendarController.class.getResource("MainAppointment.fxml"));
                                Parent calScreen = calLoader.load();
                                Scene calScene = new Scene(calScreen);
                                Stage calStage = new Stage();
                                calStage.setTitle("Appointment Calendar");
                                calStage.setScene(apptCalScene);
                                calStage.show();
                            }
                            else {
                                apptAlert.close();
                            }
                        }
                        else {
                            userLog.log(Level.INFO, "User: {0} logged in.", loggingUsers.getUserName());
                            FXMLLoader apptCalLoader = new FXMLLoader(AppointmentCalendarController.class.getResource("MainAppointment.fxml"));
                            Parent calScreen = calLoader.load();
                            Scene calScene = new Scenec(calScreen);
                            Stage calStage = new Stage();
                            calStage.setTitle("Appointment Calendar");
                            calStage.setScene(apptCalScene);
                            calStage.show();
                            Stage loginStage = (Stage) btnLogin.getScene().getWindow();
                            loginStage.close();
                        }
                    }
                    catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                catch (AssertionError e) {
                    System.out.println(e.getMessage());
                    this.lblAlert.setText(this.rb.getString("lblErrorAlert") + ".");
                    this.lblAlert.setTextFill(Paint.valueOf("RED"));
                    userLog.log(Level.WARNING, "Invalid credentials entered! User: {0}", loggingUsers.getUserName());
                }
            });
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

没有错误消息,按下按钮时没有任何反应

我们放弃了标记到按钮点击的 ActionEvent
以下是我们如何命名我们的动作事件和代码示例

屏幕截图来自 Scene Builder

    @FXML
private void onBack() throws IOException{
    stage = (Stage)childTVPane.getScene().getWindow();// pane you are ON
    paneStart = FXMLLoader.load(getClass().getResource("start.fxml"));// pane you are GOING TO
    Scene scene = new Scene(paneStart);// pane you are GOING TO
    scene.getStylesheets().add(getClass().getResource("diary.css").toExternalForm());
    stage.setScene(scene);
    stage.setTitle("Diary"); 
    stage.show();
    stage.sizeToScene();
    stage.centerOnScreen(); 
}

享受并欢迎来到 SO