null object reference [duplicate]

-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

Adapter 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;
}
    
asked by anonymous 25.10.2018 / 01:23

1 answer

1

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

inflater = activity.getLayoutInflater();

You'll need to get a replacement for the activity variable that effectively brings the Activity, perhaps passing it as an argument in the builder of your adapter. Unfortunately I can not remember right how you do it on Android. Good luck.

    
25.10.2018 / 01:43