Context must not be null


You see, I have a class which works properly for me, but, the images that are not seen on the screen are happening as if I were looking for the correct one, so I added the library of Picasso :


The application closes, and this is the logcat :

java.lang.IllegalArgumentException: Context must not be null

And this the complete code:

public class Estadisticas_Adapter extends ArrayAdapter<Estadisticas> {

    Context context;

    ArrayList<Estadisticas> Estadisticas_List;
    LayoutInflater vi;
    int Resource;
    ViewHolder holder;

    public Estadisticas_Adapter(Context context, int resource, ArrayList<Estadisticas> objects) {
        super(context, resource, objects);
        vi = (LayoutInflater) context
        Resource = resource;
        Estadisticas_List = objects;

    public View getView(int position, View convertView, ViewGroup parent) {
        // convert view = design
        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = vi.inflate(Resource, null);

            holder.escudo_local = (ImageView) v.findViewById(;
            holder.escudo_visi = (ImageView) v.findViewById(;

            holder.tv_Nombre = (TextView) v.findViewById(;
            holder.tv_Nombre_Local = (TextView) v.findViewById(;
            holder.tv_Nombre_Visi = (TextView) v.findViewById(;
            //holder.tvNombre_Arbitro = (TextView) v.findViewById(;
            holder.tv_Fecha = (TextView) v.findViewById(;
            holder.tv_Hora = (TextView) v.findViewById(;
            holder.tv_Result_Local = (TextView) v.findViewById(;
            holder.tv_Result_Visitante = (TextView) v.findViewById(;
            /*holder.tv_Targeta = (TextView) v.findViewById(;
            holder.tv_Tar_Minuto = (TextView) v.findViewById(;
            holder.tv_Gol_Minuto = (TextView) v.findViewById(;
            holder.tv_Nombre_Entra = (TextView) v.findViewById(;
            holder.tv_Dorsal_Entra = (TextView) v.findViewById(;
            holder.tv_Nombre_Sale = (TextView) v.findViewById(;
            holder.tv_Dorsal_Sale = (TextView) v.findViewById(;
            holder.tv_Cambio_Min = (TextView) v.findViewById(;*/
            holder.tv_Estado_Partido = (TextView) v.findViewById(;
            //holder.tv_Num_Goles = (TextView) v.findViewById(;
        } else {
            holder = (ViewHolder) v.getTag();



        //new DownloadImageTask(holder.escudo_local).execute(Estadisticas_List.get(position).getEscudo_local());
        new DownloadImageTask(holder.escudo_visi).execute(Estadisticas_List.get(position).getEscudo_visitante());

        holder.tv_Fecha.setText("Fecha: "+Estadisticas_List.get(position).getFecha());
        holder.tv_Hora.setText("Hora: "+Estadisticas_List.get(position).getHora());
        //holder.tv_Targeta.setText("targeta: " + Estadisticas_List.get(position).getTargeta());
        //holder.tv_Tar_Minuto.setText("Targetamin: " + Estadisticas_List.get(position).getTarMinuto());
        //holder.tv_Gol_Minuto.setText("golmin: " + Estadisticas_List.get(position).getGol_Min());
        //holder.tv_Nombre_Entra.setText("Nombreentra: " + Estadisticas_List.get(position).getNombre_Entra());
        //holder.tv_Dorsal_Entra.setText("dorsalentra: " + Estadisticas_List.get(position).getDorsal_Entra());
        //holder.tv_Nombre_Sale.setText("Nombreentrasale: " + Estadisticas_List.get(position).getNombre_Sale());
        //holder.tv_Dorsal_Sale.setText("dorsalsale: " + Estadisticas_List.get(position).getDorsal_Sale());
        //holder.tv_Cambio_Min.setText("cambiomin: " + Estadisticas_List.get(position).getCambio_Min());
        return v;


    static class ViewHolder {
        public TextView tv_Nombre;
        public TextView tv_Nombre_Local;
        public TextView tv_Result_Local;
        public TextView tv_Result_Visitante;
        public TextView tvNombre_Arbitro;
        public TextView tv_Fecha;
        public TextView tv_Hora;
        public TextView tv_Nombre_Visi;
        public TextView tv_Targeta;
        public TextView tv_Tar_Minuto;
        public TextView tv_Gol_Minuto;
        public TextView tv_Nombre_Entra;
        public TextView tv_Dorsal_Entra;
        public TextView tv_Nombre_Sale;
        public TextView tv_Dorsal_Sale;
        public TextView tv_Cambio_Min;
        public TextView tv_Estado_Partido;
        public TextView tv_Num_Goles;

        public ImageView escudo_local;
        public ImageView escudo_visi;


    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage) {
            this.bmImage = bmImage;


        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new;
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
            return mIcon11;

        protected void onPostExecute(Bitmap result) {



Can you give me a solution?

Thanks Angel Angel, the solution:

public Estadisticas_Adapter(Context context, int resource, ArrayList<Estadisticas> objects) {
        super(context, resource, objects);
        vi = (LayoutInflater) context
        Resource = resource;
        Estadisticas_List = objects;
        this.context = context;
asked by Rafel C.F 17.01.2016 в 08:26

1 answer


This part may be the one that is throwing you the error:

Context context;
public Estadisticas_Adapter(Context context, int resource,  ArrayList<Estadisticas> objects) {

    super(context, resource, objects);

You hide the context that initializes in super, you could try to use this.context = context under the constructor, if this works for you, you could refactor the code if necessary to not call context in the base class or maybe you can do it protect and not use Contex context in class Extadisticas_Adapter because it inherits it (I do not know how it is in the base class, I just leave it as an observation), or eliminate the Contex contex of the class and use the base class but I do not know if this is possible because I do not know which way is in the base class or what you will do with contex in class Extadisticas_Adapter , but basically I think it is because Contex contex is not initialized in this class but in the base class, but even if in the base class it is visible to the derived class, it is being hidden, and the one that is visible Contex contex is not initialized.

answered by 17.01.2016 / 13:04