i'm having a little problem in putting a checkbox in my jtable. there are four columns in my jtable the last 2 columns have checkboxes. the data in my jtable are from my database. this is my error "Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean", in my database there are two "yes/no" columns which are "present" and "overtime" how can i resolved this error?
this is my code
private void attendance(){
DateFormat dateFormat = new SimpleDateFormat("MMMM dd hh:mm a");
Date date = new Date();
attendanceDate.setText(dateFormat.format(date));
try{
String query ="SELECT e.firstName,e.lastName,a.Present,a.Overtime FROM employees e INNER JOIN attendance a ON e.ID = a.empID";
Object[][] result = connectToDB(query);
dailyAttendanceTable.setModel(new javax.swing.table.DefaultTableModel(
result, new String [] {"First Name","Last Name","Present","Overtime"}
)
{
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class
};
boolean[] canEdit = new boolean [] {
false, false, true, true
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
}catch (ClassNotFoundException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}