Pietro Coelho
Pietro Coelho

Reputation: 2072

JavaFX - Method for set LocalDateTime not working

I have a class called Sell which has a SimpleObjectProperty. In the POJO, the getters and setters are the following:

private ObjectProperty<LocalDateTime> sellDate;

....

public LocalDateTime getSellDate() {
    return sellDate.get();
}

public void setSellDate(LocalDateTime value) {
    sellDate.set(value);
}

When creating a new instance of the Sell class, I use the method setSellDate():

....
Sell sell = new Sell();
//another gets and sets...
sell.setSellDate(LocalDateTime.now());

This line of code is giving me a NullPointerException. What am I doing wrong?

Upvotes: 0

Views: 234

Answers (1)

James_D
James_D

Reputation: 209418

Since sell clearly isn't null, sellDate must be the reference that is null. You show where you declare it with

private ObjectProperty<LocalDateTime> sellDate;

but you don't show any code that initializes it. You need something like

sellDate = new SimpleObjectProperty<>();

in the constructor.

Upvotes: 1

Related Questions