我在片段的onCreateView()中有一个arraylist,它包含listview中要更新的数据,我使用接口回调来更新另一个活动的数据,如下所示:
listUpdatable.update(nameStr,otpStr,timeStr);
@Override
public void update(String name, String time, String otp) {
SentMessageModel message = new SentMessageModel();
message.setOtp(otp);
message.setName(name);
message.setTime(time);
messages.add(0, message);
adapter.notifyDataSetChanged();
}
app carashes on calling update方法正在arraylist上显示NPE。
我该怎么办?
View view = inflater.inflate(R.layout.fragment_sent_message_history, container, false);
ListView listView = view.findViewById(R.id.sent_message_listView);
emptyText = view.findViewById(R.id.empty_text);
messages = new ArrayList<>();
databaseCodeForAll(); // fetches the content of messages arraylist from sqlite
adapter = new SentMessageAdapter(getContext(), messages);
listView.setAdapter(adapter);