这里的代码属于类
public class AdapterOrderShop extends
RecyclerView.Adapter<AdapterOrderShop.HolderOrderShop>
implements Filterable {
private Context context;
public ArrayList<ModelOrderShop> orderShopArrayList,filterList;
private FilterOrderShop filter;
public AdapterOrderShop(Context context, ArrayList<ModelOrderShop> orderShopArrayList) {
this.context = context;
this.orderShopArrayList = orderShopArrayList;
this.filterList=orderShopArrayList;
}
@Override
public int getItemCount() {
return orderShopArrayList.size();
}
尝试对null调用虚拟方法"int java.util.ArrayList.size(("目标参考
您应该在adapter
构造函数中初始化您的列表,问题就解决了。未初始化的列表返回导致此错误发生的null。您可以在adapter
中创建构造函数,然后从activity
或fragment
传递到adapter
中声明的列表。如果您从activity
或fragment
传递context
,则您具有与下面相同的构造函数,但如果您没有传递context
,则从构造函数中移除Context
参数。
public YourAdapterName(Context mCtx, List<YourModelClassName> taskList) {
this.mCtx = mCtx;
this.orderShopArrayList= taskList;
}