null Object Reference

Asked

Viewed 80 times

-1

           Logcat

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean)' on a null object reference

Adaptor code

@Override
public View getView(int i, View convertView, ViewGroup parent) {
    View vista = convertView;

    if(vista==null)
        vista = inflater.inflate(R.layout.elemento_lista, parent, false);

    TextView titulo = (TextView) vista.findViewById(R.id.tvTitulo);
    TextView duracion = (TextView) vista.findViewById(R.id.tvDuracion);
    TextView director = (TextView) vista.findViewById(R.id.tvDirector);

    ImageView imagen = (ImageView) vista.findViewById(R.id.ivImagen);
    RatingBar calificacion = (RatingBar) vista.findViewById(R.id.ratingBarPel);

    titulo.setText(datos[i][0]);
    director.setText(datos[i][1]);
    duracion.setText("Duração " + datos[i][2]);
    imagen.setImageResource(datosImg[i]);
    calificacion.setProgress(Integer.valueOf(datos[i][3]));

    return vista;
}

1 answer

1

You have to instantiate the inflater. Try to fit this line at the beginning of the method getView():

inflater = activity.getLayoutInflater();

You will need to find a replacement for the variable activity that effectively brings Activity, perhaps passing as an argument in your adapter’s constructor. Unfortunately I do not remember how to do it right on Android. Good luck.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.