首页 > 代码库 > addAll()报NullPointer原因

addAll()报NullPointer原因

 

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

SeatBookingInfo b=new SeatBookingInfo();

b.setIndex(index);

b.setContactInfo(contactInfo);

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

b.setSeatTravelerInfo(seatTravelerInfo);

addAll()报NullPointer原因