I want to build a small game which will be a JTable
with some values and JTextField
above the table, user should type any value in the text field if it exist in the table it will remove if it not exist user will get message by that,
I tried to remove value which user write it in text field and wrote this code:
String value = txt_num.getText();
for (int i = 0; i < table.getRowCount(); i++) {
for (int j = 0; j < table.getColumnCount(); j++) {
if (tbl.getModel().getValueAt(i, j).toString().equals(value)) {
tbl.setValueAt(null, i, j);
} else {
JOptionPane.showMessageDialog(null, "Value isn't exist");
}
}
}
This code remove correctly but it remove the first value which entered but when I enter another value I got this error:
How can I resolve that NullPointerException
?