title: JTable Adding cell values
body: <p>//Tell if this needs more info</p>
  
  <p>I want to add the integers inside a cell in a column.
  Here's my code:</p>
  
  <pre><code>// it's in a mouse listener, eveything works fine, but what I want to do is to add
  // the values (for ex. 300,400,500) 
  
      public void mouseClicked(MouseEvent e) {
  
      if(e.getClickCount() == 2) {
          JTable tbl = (JTable)e.getSource();
          int selectedRow = tbl.getSelectedRow();
          int tbl1_col = 0; // table 1's column to get the data from
          int tbl2_col = 0; // table 2's column to put the data to
  
     ((DefaultTableModel)tbl2.getModel()).addRow(new Object[] {null,null,null,null}); 
     //to automatically add a new row
  
      while(tbl1_col&lt;tbl1.getColumnCount()) {
              tbl2.setValueAt(tbl1.getValueAt(selectedRow,tbl1_col),tbl2_row,tbl2_col);
              // Setting the value to be put on to table 2 from table 1
  
              System.out.println(tbl2.getValueAt(tbl2_row,3));
  
              tbl1_col++;
              tbl2_col++;
  
                  if(rcol==tbl1.getColumnCount()){
                              tbl2_row++;
                  }
  
                  label.setText(String.valueOf(totalAmount));
       }
  }
  </code></pre>
  
  <p>There's a System.out.println over there to see what values are inside
  and the outputs were:</p>
  
  <pre><code>null null null 300
  </code></pre>
  
  <p>My code to add the values:</p>
  
  <pre><code>totalAmount = totalAmount + (int) tbl2.getValueAt(tbl2_row,3));
  </code></pre>
  
  <p>The error I get:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  </code></pre>