我有一个可扩展的Recycler,我从服务器获取数据,我检查日志,我得到的数据是正确的,现在当我尝试设置适配器时,我收到了这个错误
java.lang.NullPointerException:尝试调用接口方法 null对象上的'java.util.Iterator java.util.List.iterator()' 参考
这是我的片段
private List<GetInboxByUserNameModel.DATum> messageslist;
private GetInboxByUserNameModel getInboxByUserNameModel;
private RecyclerView recyclerView;
messageslist = new ArrayList<>();
getInboxByUserNameModel = (GetInboxByUserNameModel) responseObject;
messageslist = getInboxByUserNameModel.getDATA();
implementAdapter(messageslist);
private void implementAdapter(List<GetInboxByUserNameModel.DATum> categoriesList) {
if (categoriesList == null) {
AlertView.showOneButtonAlert(getActivity(), getActivity(), "", getString(R.string.no_data), getString(R.string.ok), null);
return;
}
if (categoriesList.size() == 0) {
AlertView.showOneButtonAlert(getActivity(), getActivity(), "", getString(R.string.no_data), getString(R.string.ok), null);
return;
}
mAdapter = new RecipeAdapterForInbox_Test(getActivity(), categoriesList);
mAdapter.setExpandCollapseListener(new ExpandableRecyclerAdapter.ExpandCollapseListener() {
@UiThread
@Override
public void onParentExpanded(int parentPosition) {
}
@UiThread
@Override
public void onParentCollapsed(int parentPosition) {
}
});
recyclerView.setAdapter(mAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
这是我的ExpandableRecyclerAdapter
public class RecipeAdapterForInbox_Test extends ExpandableRecyclerAdapter<GetInboxByUserNameModel.DATum, GetInboxByUserNameModel.MESSAGES, ViewHolderParentInbox, ViewHolderChildinbox> {
private LayoutInflater mInflater;
private Activity activity;
private Context context;
List<GetInboxByUserNameModel.DATum> daTa;
public RecipeAdapterForInbox_Test(Activity activity, List<GetInboxByUserNameModel.DATum> recipeList) {
super(recipeList);
this.daTa = recipeList;
this.activity = activity;
this.context = activity;
mInflater = LayoutInflater.from(context);
}
@UiThread
@Override
public ViewHolderParentInbox onCreateParentViewHolder(@NonNull ViewGroup parentViewGroup, int viewType) {
View recipeView = mInflater.inflate(R.layout.new_adapter_available_parent, parentViewGroup, false);
return new ViewHolderParentInbox(recipeView, context);
}
@UiThread
@Override
public ViewHolderChildinbox onCreateChildViewHolder(@NonNull ViewGroup childViewGroup, int viewType) {
View ingredientView = mInflater.inflate(R.layout.new_adapter_available_child, childViewGroup, false);
return new ViewHolderChildinbox(ingredientView);
}
@UiThread
@Override
public void onBindParentViewHolder(@NonNull ViewHolderParentInbox holder, int parentPosition, @NonNull GetInboxByUserNameModel.DATum model) {
holder.headerNameTextView.setText(model.getbILLINGNUMBER());
}
@UiThread
@Override
public void onBindChildViewHolder(@NonNull ViewHolderChildinbox holder, int parentPosition, int childPosition, final GetInboxByUserNameModel.MESSAGES model) {
holder.childTextview.setText(model.getbRIEF());
// holder.activateButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// goDialog(model);
// }
// });
}
我使用了调试,问题就在这里
super(recipeList);
如果有人对此有任何疑问,请帮助我
答案 0 :(得分:0)
由于组内的子列表为null
,因此您发现此错误。请遍历messageslist
并检查该组并获取子列表。