0
private void calculateTotalValue() {
    DefaultTableModel dtm=(DefaultTableModel) tableDetail.getModel();
    double total=0;
    for(int i=0;i<dtm.getRowCount();i++){
        total =total+(double)dtm.getValueAt(i, 4);
    }
    totallbl.setText(Double.toString(total));
}

total =total+(double)dtm.getValueAt(i, 4); this line throws the NullPointerException But I can't understand why it is happening?

dave
  • 575
  • 4
  • 19
  • Post your logs here, check your `tableDetail.getModel()` basically the `dtm` object and this could be `dtm.getValueAt(i, 4)` returning null. – robot_alien Jul 25 '18 at 14:52
  • 1
    @Ivar In that case `dtm` would be null and the line above would already throw a NPE. Should be `dtm.getValueAt(i, 4)` that returns null and throws a NPE when casting to double. – OH GOD SPIDERS Jul 25 '18 at 14:52

0 Answers0