Cannot resolve method 'with(Context)'

421 Views Asked by At

I am using the latest version of android studio this my adapter program this was used in my previous projects glide version: 4.14.2 the context is showing the following error Cannot resolve method 'with(Context)'.

package com.example.mystorein.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mystorein.R;
import com.example.mystorein.modal.Restaurent;
import com.google.api.Context;

import java.util.ArrayList;

public class RestaurentAdapter extends RecyclerView.Adapter<RestaurentAdapter.ViewHolder> {

   Context context;
   ArrayList<Restaurent> list;

   public RestaurentAdapter(Context context, ArrayList<Restaurent> list) {
       this.context = context;
       this.list = list;
   }

   @NonNull
   @Override
   public RestaurentAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       return new      ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.toprated_near_item,parent,false));
      }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

       Glide.with(context).load(list.get(position)).into(holder.Img);
       holder.name.setText(list.get(position).getName());
       holder.delTime.setText(list.get(position).getTime());

    }

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

   public static class ViewHolder extends RecyclerView.ViewHolder {

       ImageView Img;
       TextView name, delTime;

       public ViewHolder(@NonNull View itemView) {
           super(itemView);

           Img = itemView.findViewById(R.id.Img);
           name = itemView.findViewById(R.id.name);
          delTime = itemView.findViewById(R.id.delTime);

       }
    }
}

I'd like to know the reason for this error and any suggestions to solve this

1

There are 1 best solutions below

0
On

The error Cannot resolve method 'with(Context)' occurs because the wrong Context class has been imported. The code has imported com.google.api.Context instead of android.content.Context.

To fix this error, you need to replace the incorrect import statement:

import com.google.api.Context;

with the correct import statement:

import android.content.Context;