为什么我有一个NullPointerException当我设置Calendar.getInstance()在模型的属性



在我的模型中,我有这个:

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

在eclipse调试器中,我在这行中有一个NullPointerException:

plan.setCreationDate(instance);

可能您的plan对象没有实例化…

这将防止异常:

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

最新更新