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?

7
  • Which line is the exception happening on? Commented Jul 25, 2016 at 9:04
  • This line ` totalWithDiscount.set(totalWithoutDiscount.get().add(s.getAmount()));` Commented Jul 25, 2016 at 9: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. Commented Jul 25, 2016 at 9:09
  • System.out.print(s.getAmount()) tells me s.getAmount() is not null. Commented Jul 25, 2016 at 9:14
  • So, that leaves three more possibilities. And please, use the debugger, rather than putting System.out.println all over the place. Commented Jul 25, 2016 at 9:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.