-2

Please someone can fix this error :

java.lang.IllegalArgumentException: You cannot start a load on a null Context

public class CompteAdapter extends RecyclerView.Adapter<CompteAdapter.MyViewHolder> {

    private Context mContext;
    private List<CompteWrapper> compteList;
    private AdapterView.OnItemClickListener onItemClickListener;

    public CompteAdapter(Context mContext, AdapterView.OnItemClickListener onItemClickListener, List<CompteWrapper> compteList) {
        this.mContext = mContext;
        this.compteList = compteList;
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.compte_carte, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        CompteWrapper compte = compteList.get(position);
        holder.title.setText(compte.getName());

        Picasso.with(this.mContext).load(compte.getIcon()).into(holder.icon);
    }
}
david.mihola
  • 10,142
  • 5
  • 41
  • 62
  • What is `this.mContext` here? may be it is null – Mayur Raval Mar 09 '17 at 09:31
  • Your `this.mContext` is null. From which place you call this? Can you share full sample of the code – Volodymyr Mar 09 '17 at 09:32
  • Post more code of your class please – Skizo-ozᴉʞS Mar 09 '17 at 09:36
  • Well, of course this is *not* an "exact duplicate" of "What is NullPointerException". The question is: Why is the `Context` `null` here? You may be passing `null` in your constructor. Instead of fixing that I would just remove that parameter altogether and use `Picasso.with(holder.icon.getContext())...` – david.mihola Mar 09 '17 at 10:49

1 Answers1

-1

Using getApplicationContext() or getBaseContext()

Moeen Kashisaz
  • 302
  • 1
  • 2
  • 12