Android Recycler 视图中 Picasso 的非法参数异常

Illegal Argument Exception at Picasso in Android Recycler view

我需要使用 Picasso 库将图像放入图像视图下面是我的代码

 Picasso.get().load(mFilteredList.get(position).getViewProductImage()).into(holder.imageView);

但我收到类似

的错误

java.lang.IllegalArgumentException: Target must not be null. at com.squareup.picasso.RequestCreator.into(RequestCreator.java:682) at com.squareup.picasso.RequestCreator.into(RequestCreator.java:665)

谁能告诉我如何将图像放入 imagesView 中。下面是我的适配器class

public class ViewAllAdapter extends RecyclerView.Adapter<ViewAllAdapter.ViewAllViewHolder> {

    List<String> listOfIds=new ArrayList<>();
    ArrayList<ViewAllObject> data;
    Context myContext;
    private ImageView imageView;
    private ArrayList<ViewAllObject> mFilteredList;
    public ViewAllAdapter(List<ViewAllObject> data){
        this.data= (ArrayList<ViewAllObject>) data;
        this.mFilteredList = (ArrayList<ViewAllObject>) data;
    }

    @NonNull
    @Override
    public ViewAllViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
        myContext = parent.getContext();
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.view_all_items,parent,false);
        final TextView textView=(TextView)view.findViewById(R.id.view_all_product_vendor_name);
        final TextView textView1=(TextView)view.findViewById(R.id.view_all_product_title);
        return new ViewAllViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewAllViewHolder holder, int position) {
        final ViewAllObject viewAllObject=data.get(position);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(myContext,DescriptionActivity.class);
                i.putExtra("productname",viewAllObject.getVendorName());
                i.putExtra("title",viewAllObject.getProductsTitle());
                i.putExtra("description",viewAllObject.getProductDescription());
                i.putStringArrayListExtra("imagesList", (ArrayList<String>) viewAllObject.getImagesList());
                i.putExtra("productSet",viewAllObject.getProductSet());
                i.putExtra("productQuantity",viewAllObject.getAvalibileQuantity());
                i.putExtra("productId",viewAllObject.getProductId());
                i.putExtra("productImage",viewAllObject.getViewProductImage());
                i.putExtra("productType",viewAllObject.getViewAllProductType());
                i.putExtra("productPrice",viewAllObject.getViewAllPrice());
                myContext.startActivity(i);
            }
        });
        LinearLayout addToCartIcon=(LinearLayout) holder.itemView.findViewById(R.id.view_all_items_cart_icon);

        addToCartIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<Long> lisId=new ArrayList<>();
                List<CartItemsTable> cartItems=Almirah.cartDB.MyDao().getCartItems();
                for (CartItemsTable cartItemsTable1:cartItems) {

                long productId = cartItemsTable1.getProductId();
                lisId.add(productId);

            }
            boolean newItem = true;
            for (int i=0;i<lisId.size();i++){
                if (viewAllObject.getProductId() == lisId.get(i)){
                    newItem = false;
                    AlertDialog.Builder builder;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        builder = new AlertDialog.Builder(myContext, android.R.style.Theme_Material_Dialog_Alert);
                    } else {
                        builder = new AlertDialog.Builder(myContext);
                    }
                    builder.setMessage("Item Already In Cart")
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                }
                            })
                            .setIcon(android.R.drawable.ic_dialog_alert)
                            .show();
                }
            }
            if (newItem) {
                String date = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());
                Gson gson = new Gson();
                Type type = new TypeToken<List<String>>() {}.getType();
                String imagesList = gson.toJson(viewAllObject.getImagesList(), type);

                CartItemsTable cartItemsTable = new CartItemsTable();
                cartItemsTable.setVendorName(viewAllObject.getVendorName());
                cartItemsTable.setProductsTitle(viewAllObject.getProductsTitle());
                cartItemsTable.setViewAllPrice(viewAllObject.getViewAllPrice());
                cartItemsTable.setProductSet(viewAllObject.getProductSet());
                cartItemsTable.setAvalibileQuantity(viewAllObject.getAvalibileQuantity());
                cartItemsTable.setProductId(viewAllObject.getProductId());
                cartItemsTable.setViewAllProductType(viewAllObject.getViewAllProductType());
                cartItemsTable.setViewProductImage(viewAllObject.getViewProductImage());
                cartItemsTable.setQuantity(1);
                cartItemsTable.setDate(date);
                cartItemsTable.setProductDescription(viewAllObject.getProductDescription());
                 cartItemsTable.setImagesList(imagesList);
                ALmirah.cartDB.MyDao().addCartItems(cartItemsTable);

                int cartCount=Integer.parseInt(ActivityForViewAll.countTextview.getText().toString());
                ActivityForViewAll.countTextview.setText((cartCount+1)+"");

                ActivityForViewAll.countTextview.setVisibility(View.VISIBLE);

                Toast  toast=Toast.makeText(myContext, viewAllObject.getProductsTitle() + " Added to cart", Toast.LENGTH_SHORT);
                View view1 = toast.getView();
                view1.getBackground().setColorFilter(Color.parseColor("#FFF7D3A5"), PorterDuff.Mode.SRC_IN);
                toast.show();

            }
            }
        });
    // holder.bindItems(viewAllObject);
        holder.viewAllProductVendorName.setText(mFilteredList.get(position).getVendorName());
       holder.viewAllProductTitle.setText(mFilteredList.get(position).getProductsTitle());
        holder.viewAllProductType.setText(mFilteredList.get(position).getViewAllProductType());
        holder.viewAllProductPrice.setText(mFilteredList.get(position).getViewAllPrice()+"SR");
     Picasso.get().load(mFilteredList.get(position).getViewProductImage()).into(holder.imageView); Picasso.get().load(viewAllObject.getViewProductImage()).into(imageView);

    }

    @Override
    public int getItemCount() {
        return mFilteredList.size();
    }

    public Filter getFilter() {
        return new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence charSequence) {

                String charString = charSequence.toString();

                if (charString.isEmpty()) {

                    mFilteredList = data;
                } else {

                    ArrayList<ViewAllObject> filteredList = new ArrayList<>();

                    for (ViewAllObject viewAllObject : data) {

                        if (viewAllObject.getProductsTitle().toLowerCase().contains(charString) || viewAllObject.getViewAllProductType().toLowerCase().contains(charString) || viewAllObject.getViewAllPrice().toLowerCase().contains(charString)) {

                            filteredList.add(viewAllObject);
                        }
                    }

                    mFilteredList = filteredList;
                }

                FilterResults filterResults = new FilterResults();
                filterResults.values = mFilteredList;
                return filterResults;
            }

            @Override
            protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
                mFilteredList = (ArrayList<ViewAllObject>) filterResults.values;
                notifyDataSetChanged();
            }
        };
    }

    public class ViewAllViewHolder extends RecyclerView.ViewHolder{ 
        private TextView viewAllProductVendorName,viewAllProductTitle,viewAllProductType,viewAllProductPrice; 
        private ImageView imageView;

        public ViewAllViewHolder(@NonNull View itemView) {
            super(itemView);
             viewAllProductVendorName=(TextView)itemView.findViewById(R.id.view_all_product_vendor_name);


            ImageView imageView=(ImageView)itemView.findViewById(R.id.card_view_all_img);

           viewAllProductTitle=(TextView)itemView.findViewById(R.id.view_all_product_title);

           viewAllProductType=(TextView)itemView.findViewById(R.id.view_all_product_type);

           viewAllProductPrice=(TextView)itemView.findViewById(R.id.view_all_product_price);

        }
    } }

改变

ImageView imageView = (ImageView) itemView.findViewById(R.id.card_view_all_img);

imageView = (ImageView) itemView.findViewById(R.id.card_view_all_img);