0

I'm trying to pass the data from the JTable for which all the types are String then I want to pass to the JDateChooser when the user selected the row in the table. But I tried parsing the date from string to date type but still, I got an error saying illegal value.

Here is the code.

private void tableDataMouseClicked(java.awt.event.MouseEvent evt) {
    try{
        DefaultTableModel model = (DefaultTableModel) tableData.getModel();
        int selectedRowIndex = tableData.getSelectedRow(); //get selected row
        Fname.setText(model.getValueAt(selectedRowIndex,1).toString());
        Lname.setText(model.getValueAt(selectedRowIndex,2).toString());
        ageSpin.setValue(model.getValueAt(selectedRowIndex,3).toString());
        Date date = new SimpleDateFormat("yyyy-MM-dd").parse((String)model.getValueAt(selectedRowIndex, 4).toString());
        dob.setDate(date);
        addressField.setText(model.getValueAt(selectedRowIndex,5).toString());
        phoneNumField.setText(model.getValueAt(selectedRowIndex,6).toString());
        emailField.setText(model.getValueAt(selectedRowIndex,7).toString());
    }catch(ParseException e){
        e.printStackTrace();
        Logger.getLogger(addCitizzen.class.getName()).log(Level.SEVERE, null, e);
    }
}

Here is the error I'm getting:

java.lang.IllegalArgumentException: illegal value

The program gives an error when it reaches the Date part.

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
  • 3
    A better choice would be to allow the model to support a `Date` object – MadProgrammer Nov 24 '21 at 08:45
  • [Edit] your question and post the entire [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors). – Abra Nov 24 '21 at 11:56
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 28 '21 at 15:56

0 Answers0