0

I want to sum the ObjectProperty<BigDecimal> values of a JavaFX TableColumn. I've used this question as a reference. The problem is my implementation of it as shown here:

private void doSalesTotals() {
olSales.addListener(new ListChangeListener<Sales>() {
  @Override
  public void onChanged(Change<? extends Sales> change) {
    while (change.next()){
      if (change.wasAdded()){
        for (Sales s : change.getAddedSubList()){
          totalWithDiscount.set(totalWithoutDiscount.get().add(s.getAmount()));
          System.out.print(totalWithDiscount);

        }
      } else if (change.wasRemoved()){

      } else if (change.wasReplaced()){

      } else if (change.wasUpdated()){

      }
    }
  }
});

keeps giving me a nullpointer exception and no currency addition takes place.

Some context: The table is part of a POS module I'm doing for my 4th year Undergraduate project.

What exactly am I doing wrong and how do I solve it?

Community
  • 1
  • 1
MusH
  • 85
  • 2
  • 9
  • Which line is the exception happening on? – Dawood ibn Kareem Jul 25 '16 at 09:04
  • This line ` totalWithDiscount.set(totalWithoutDiscount.get().add(s.getAmount()));` – MusH Jul 25 '16 at 09:07
  • 1
    So that could mean one of four things. Either `s` is null, or `totalWithDiscount` is null, or `totalWithoutDiscount` is null, or `totalWithoutDiscount.get()` is null. Your debugger will tell you which. – Dawood ibn Kareem Jul 25 '16 at 09:09
  • `System.out.print(s.getAmount())` tells me s.getAmount() is not null. – MusH Jul 25 '16 at 09:14
  • So, that leaves three more possibilities. And please, use the debugger, rather than putting `System.out.println` all over the place. – Dawood ibn Kareem Jul 25 '16 at 09:16
  • kindly take a better look at the question before marking it as a duplicate of something that doesn't help me solve my problem. – MusH Jul 25 '16 at 09:23
  • If you follow the advice in the answers to that question, it WILL solve your problem. Your problem is a null pointer exception. That question tells you how to deal with null pointer exceptions. So do my comments here. – Dawood ibn Kareem Jul 25 '16 at 09:24

0 Answers0