如何在Java中调试JOption错误消息?

时间:2017-04-27 17:23:21

标签: java swing exception-handling joptionpane numberformatexception

我正在做一个学校管理系统项目,一切都很好,除非我尝试点击保存按钮时它返回JOption错误消息,即手机必须是整数,尽管它已经是。我必须说我有一个类似的教师注册表格,一个有效。怎么会这样?

private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {                                            
try{    
        int day = Integer.valueOf((String)jComboBoxDay.getSelectedItem());
        int month = Integer.valueOf((String)jComboBoxMonth.getSelectedItem());
        int year = Integer.valueOf((String)jComboBoxYear.getSelectedItem());
        String birthDate = ""+day+month+year;
        String firstName = jTextFieldFirstName.getText();            
        String lastName = jTextFieldLastName.getText();
        String address = jTextFieldAddress.getText();
        String email = jTextFieldEmail.getText();
        int phoneNumber = Integer.parseInt((jTextFieldPhoneNumber).getText());
        String gender = (String)jComboBoxGender.getSelectedItem(); 
        String religion = jTextFieldReligion.getText();
        String contactTeacher =jTextFieldContactTeacher.getText();
        int contactPhoneNumber = Integer.parseInt((jTextFieldContactPhoneNumber).getText());
        int momID = Integer.parseInt((jTextFieldMotherID).getText());
        int fatherID = Integer.parseInt((jTextFieldFatherID).getText());

        Reset();
            Students student = new Students(birthDate,firstName,lastName,address, email,phoneNumber,gender,religion,contactTeacher,contactPhoneNumber,momID,fatherID);
            studentsControl.createStudents(student);
            loadTable();
    } 
            catch (NumberFormatException exception)
    {
        JOptionPane.showMessageDialog(null,"Phone must be an integer ","Error",JOptionPane.ERROR_MESSAGE);
        jTextFieldPhoneNumber.setText("");
}
}             

1 个答案:

答案 0 :(得分:0)

您正在从month对象获取jComboBoxMonth说明。

尝试通过调用getSelectedItem方法并添加1来获取索引。