Based on this stack trace:
array index out of bound exceptionjava.lang.ArrayIndexOutOfBoundsException: 6 >= 6
array index out of bound exceptionjava.lang.ArrayIndexOutOfBoundsException: 7 >= 6
array index out of bound exceptionjava.lang.ArrayIndexOutOfBoundsException: 8 >= 6
Your problem is here:
int b = table.getRowCount();
for (int i = 0; i < b; i++) {
...
if (!(str1 == null)) {
((DefaultTableModel)table.getModel()).removeRow(i);
...
}
...
}
If you remove a row from the table model within the for
loop then b
won't be longer equals to table.getRowCount()
but greater instead, causing an ArrayIndexOutOfBoundsException
.
I would replace it by this:
DefaultTableModel model = (DefaultTableModel)table.getModel();
for (int i = model.getRowCount() - 1; i >= 0; i--) { // ends condition is updated dinamically
...
if (str1 != null) {
model.removeRow(i);
...
}
...
}
Side note
There's no need to repaint the table when model data has changed (insert/update/delete). The model will notify the view in such event and this one will be updated.