При запуске фрагмента с ресайклерами выдает такую ошибку
java.lang.NullPointerException: Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$ViewHolder.itemView' on a null object reference
Fragment где должны показываться recycler view
ItemsetestAdapter itemsetestAdapter;
ArrayList<ParentItem>parentItemArrayList;
ArrayList<ChildrenItems>childrenItemsArrayList;
private RecyclerView reccart;
String[]tovarcartShopuid={"Uidfigi","opddopddpdp","flfofofof"};
String[]tovarname={"Burger","Salo","Cola"};
int[]tovarImage={R.drawable.apteka,R.drawable.cake,R.drawable.clietu};
int[]MagLogo={R.drawable.apteka,R.drawable.build,R.drawable.butt};
parentItemArrayList=new ArrayList<>();
childrenItemsArrayList=new ArrayList<>();
for (int i=0;i<tovarcartShopuid.length;i++){
ParentItem parentItem=new ParentItem(tovarcartShopuid[i],"Productsmagaz",MagLogo[i]);
parentItemArrayList.add(parentItem);
if (i<tovarname.length){
ChildrenItems childrenItems=new ChildrenItems(tovarname[i],"test","test2","test3","test4",tovarImage[i]);
childrenItemsArrayList.add(childrenItems);
}
}
itemsetestAdapter=new ItemsetestAdapter(getActivity(),parentItemArrayList,childrenItemsArrayList);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
reccart.setLayoutManager(linearLayoutManager);
reccart.setAdapter(itemsetestAdapter);
ParentItem class
public class ParentItem {
String tovarcartShopuid,MagName;
int MagLogo;
public ParentItem(){
}
public ParentItem(String tovarcartShopuid,String MagName,int MagLogo) {
this.tovarcartShopuid = tovarcartShopuid;
this.MagLogo=MagLogo;
this.MagName=MagName;
}
public int getMagLogo() {
return MagLogo;
}
public void setMagLogo(int magLogo) {
MagLogo = magLogo;
}
public String getMagName() {
return MagName;
}
public void setMagName(String magName) {
MagName = magName;
}
public String getTovarcartShopuid() {
return tovarcartShopuid;
}
public void setTovarcartShopuid(String tovarcartShopuid) {
this.tovarcartShopuid = tovarcartShopuid;
}
}
ChildrenItems
public class ChildrenItems {
private String tovarcartShopuid,TovarValue,ProductId,Price,tovarname;
int tovarImage;
public ChildrenItems(){
}
public ChildrenItems(String tovarcartShopuid, String tovarValue, String productId, String price, String tovarname,int tovarImage) {
this.tovarcartShopuid = tovarcartShopuid;
this. TovarValue = tovarValue;
this. ProductId = productId;
this. Price = price;
this.tovarname = tovarname;
this.tovarImage = tovarImage;
}
public int getTovarImage() {
return tovarImage;
}
public void setTovarImage(int tovarImage) {
this.tovarImage = tovarImage;
}
public String getTovarcartShopuid() {
return tovarcartShopuid;
}
public void setTovarcartShopuid(String tovarcartShopuid) {
this.tovarcartShopuid = tovarcartShopuid;
}
public String getTovarValue() {
return TovarValue;
}
public void setTovarValue(String tovarValue) {
TovarValue = tovarValue;
}
public String getProductId() {
return ProductId;
}
public void setProductId(String productId) {
ProductId = productId;
}
public String getPrice() {
return Price;
}
public void setPrice(String price) {
Price = price;
}
public String getTovarname() {
return tovarname;
}
public void setTovarname(String tovarname) {
this.tovarname = tovarname;
}
}
ItemsetestAdapter class
public class ItemsetestAdapter extends RecyclerView.Adapter<ItemsetestAdapter.ViewHolder> {
private Activity activity;
ArrayList<ParentItem>parentItemArrayList;
ArrayList<ChildrenItems>childrenItemsArrayList;
public ItemsetestAdapter(Activity activity, ArrayList<ParentItem> parentItemArrayList, ArrayList<ChildrenItems> childrenItemsArrayList) {
this.activity = activity;
this.parentItemArrayList = parentItemArrayList;
this.childrenItemsArrayList = childrenItemsArrayList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ParentItem parentItem=parentItemArrayList.get(position);
ChildAdapter childAdapter=new ChildAdapter(childrenItemsArrayList);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(activity);
holder.nestedrecer.setLayoutManager(linearLayoutManager);
holder.nestedrecer.setAdapter(childAdapter);
holder.textitogParent.setText(parentItem.tovarcartShopuid);
Transformation transformation=new RoundedTransformationBuilder().borderColor(Color.WHITE).borderWidthDp(3).cornerRadius(15).oval(false).build();
Picasso.get().load(parentItem.MagLogo).transform(transformation).into(holder.roundedImagemaglogo);
}
@Override
public int getItemCount() {
return parentItemArrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
RoundedImageView roundedImagemaglogo;
RecyclerView nestedrecer;
TextView textitogParent;
AppCompatButton buylist;
ImageView imagedeletemag;
public ViewHolder(@NonNull View itemView) {
super(itemView);
nestedrecer=itemView.findViewById(R.id.nestedrecer);
buylist=itemView.findViewById(R.id.buylist);
textitogParent=itemView.findViewById(R.id.textitogParent);
roundedImagemaglogo=itemView.findViewById(R.id.roundedImagemaglogo);
imagedeletemag=itemView.findViewById(R.id.imagedeletemag);
}
}
}
ChildAdapter
public class ChildAdapter extends RecyclerView.Adapter<ChildAdapter.ViewHolder> {
ArrayList<ChildrenItems>childrenItemsArrayList;
public ChildAdapter(ArrayList<ChildrenItems> childrenItemsArrayList) {
this.childrenItemsArrayList = childrenItemsArrayList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.child_item,parent,false);
return null;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ChildrenItems childrenItems=childrenItemsArrayList.get(position);
holder.textnamechild.setText(childrenItems.getTovarname());
holder.tovarcartchild.setText(childrenItems.getTovarValue());
holder.textpricechildtovar.setText(childrenItems.getTovarValue());
Transformation transformation=new RoundedTransformationBuilder().borderColor(Color.WHITE).borderWidthDp(3).cornerRadius(15).oval(false).build();
Picasso.get().load(childrenItems.getTovarImage()).transform(transformation).into(holder.imagetovarchild);
}
@Override
public int getItemCount() {
return childrenItemsArrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
RoundedImageView imagetovarchild;
TextView textnamechild,textpricechildtovar,tovarpluschildto,tovarminuschildto,tovarcartchild;
public ViewHolder(@NonNull View itemView) {
super(itemView);
tovarpluschildto=itemView.findViewById(R.id.tovarpluschildto);
tovarminuschildto=itemView.findViewById(R.id.tovarminuschildto);
textpricechildtovar=itemView.findViewById(R.id.textpricechildtovar);
imagetovarchild=itemView.findViewById(R.id.imagetovarchild);
tovarcartchild=itemView.findViewById(R.id.tovarcartchild);
textnamechild=itemView.findViewById(R.id.textnamechild);
}
}
}