我正在做一个学校管理系统项目,一切都很好,除非我尝试点击保存按钮时它返回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("");
}
}
答案 0 :(得分:0)
您正在从month
对象获取jComboBoxMonth
说明。
尝试通过调用getSelectedItem
方法并添加1
来获取索引。