0

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.

user44649
  • 1
  • 1
  • Model2 is jtable2.getmodel () – user44649 Oct 21 '15 at 03:49
  • Why was the question closed? The duplicate question didn't help at all – user44649 Oct 21 '15 at 04:07
  • 2
    The question was closed because you 1. Have an identifiable `NullPointerException` and 2. Did not provide any runnable code which demonstrates you problem which would provide any hint of what the problem might be. There is simply no means by which any body can accurately answer your question which doesn't involve making assumptions and guess work. The duplicate question is intended to provide you with ideas and recommendations on how you might identify and otherwise debug your own code, which you should have done, in order to identify the cause of your exception – MadProgrammer Oct 21 '15 at 04:10
  • See also [*Sorting and Filtering*](https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting). – trashgod Oct 21 '15 at 09:53

0 Answers0