FXCollections.observableArrayList nullpointer

时间:2016-03-11 19:39:24

标签: java javafx nullpointerexception setter

希望有人可以帮我解决这个问题。 我尝试为一堂课做一个Junit考试。 但不知何故,当我尝试创建一个要测试的对象时,我总是会收到nullpointer。

我的二年级学生在课堂上出了问题。

private ReservatieSpecificatie geselecteerdeResSpec;
private long id;
private GebruikerRepository gebruikerRepository;
DBCommunicatie databank = new DBCommunicatie();
private SimpleListProperty reservaties = new SimpleListProperty();
private SimpleObjectProperty ophaalMoment = new SimpleObjectProperty();
private SimpleObjectProperty indienMoment = new SimpleObjectProperty<>();
private SimpleStringProperty email = new SimpleStringProperty();

public Reservatie(Calendar ophaalMoment, Calendar indienMoment, List<ReservatieSpecificatie> reservaties, String email) {
    gebruikerRepository = new GebruikerRepository(databank);
    setOphaalMoment(ophaalMoment);
    setIndienMoment(indienMoment);
    setReservaties(reservaties);
    setEmail(email);

}

   public void setReservaties(List<ReservatieSpecificatie> reservaties) {
            this.reservaties.set(FXCollections.observableArrayList(reservaties));
        }

我接受了这个错误的轨道:

java.lang.NullPointerException
    at java.util.AbstractCollection.addAll(AbstractCollection.java:343)
    at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:99)
    at javafx.collections.FXCollections.observableArrayList(FXCollections.java:341)
    at domein.Reservatie.setReservaties(Reservatie.java:133)
    at domein.Reservatie.<init>(Reservatie.java:65)
    at domein.ReservatieTest.setUp(ReservatieTest.java:45)

提前感谢。

1 个答案:

答案 0 :(得分:0)

AbstractCollection.addAll() NullPointerException中,当&#34;指定的集合包含null元素且此集合不允许null元素时,您会看到reservaties被抛出,或者如果指定的集合为null。&#34;因此,val()参数本身为null,或者更可能是包含null元素。