I have a JTable, which was built in Netbeans, with a column that is set to Boolean value. To obtain the rows that were checked, the user has to click the 'Reorder' button which checks the table to see which rows were selected.column settings
The code that is supposed to find the stock id based on if the JCheckBox is checked is as follows:
for(int i=0; i<jTable2.getModel().getRowCount(); i++){
boolean check = (Boolean) jTable2.getModel().getValueAt(i, 4);
if(check){
Object o = (Object)model2.getValueAt(i, 0);
int stockID = Integer.parseInt(o.toString());
System.out.println(stockID);
}
}
Note that model2 is jTable2.getModel(). The above code throws the NullPointerException. If I print out
jTable2.getModel().getRowCount()
I will get the accurate row count. If I print out
boolean check = (Boolean) jTable2.getModel().getValueAt(2, 4)
I will get the accurate boolean value. But it throws the exception when I use the code in a for loop.