Thiago B A Salles Thiago B A Salles - 3 months ago 9
Java Question

Why i have a NullPointerException when i set Calendar.getInstance() in a attribute of model?

In my model i have this:

@Entity
public class Plan {
...
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Calendar creationDate;
...


In eclipse debugger, i have a NullPointerException in this line:

plan.setCreationDate(instance);

Answer

Probably your plan object isn't instantiated...

This will prevent the exception:

if (plan != null){
    plan.setCreationDate(instance);
}