addAll()报NullPointer原因

如下代码在注释行会报错,原因是:getSeatTravelerInfo()时值为空,对空对象addAll会报错

SeatBookingInfo b=new SeatBookingInfo();

b.setIndex(index);

b.setContactInfo(contactInfo);

// b.getSeatTravelerInfo().addAll(seatTravelerInfo);

b.setSeatTravelerInfo(seatTravelerInfo);

原文地址:https://www.cnblogs.com/shoubianxingchen/p/4267957.html