Что значит ошибка и как ее исправить
NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
Вот LogCat
ava.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
at com.example.asus.testapp.ContentAdapter.onBindViewHolder(ContentAdapter.java:46)
at com.example.asus.testapp.ContentAdapter.onBindViewHolder(ContentAdapter.java:12)
Logcat указывает на
строчку 12
public class ContentAdapter extends RecyclerView.Adapter<ContentAdapter.ViewHolder> {
и
строчку 46
CardFeed cardfeed = cardfeedlist.get(position);
Вот код самого ContentAdapter.
package com.example.asus.testapp;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class ContentAdapter extends RecyclerView.Adapter<ContentAdapter.ViewHolder> {
private List<CardFeed> cardfeedlist;
public ContentAdapter(List<CardFeed> cardfeed) {
this.cardfeedlist = cardfeed;
}
private static final int LENGTH = 18;
public static class ViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView cvUser;
TextView cvLocation;
ImageView cvPhoto;
TextView cvContent;
public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
super(inflater.inflate(R.layout.card_feed, parent, false));
cvUser = (TextView) itemView.findViewById(R.id.card_user);
cvLocation = (TextView) itemView.findViewById(R.id.card_location);
cvPhoto = (ImageView) itemView.findViewById(R.id.card_image);
cvContent = (TextView) itemView.findViewById(R.id.card_text);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
CardFeed cardfeed = cardfeedlist.get(position);
holder.cvUser.setText(cardfeed.getName());
holder.cvLocation.setText(cardfeed.getLocation());
holder.cvContent.setText(cardfeed.getDescription());
holder.cvPhoto.setImageResource(cardfeed.getPhoto());
}
@Override
public int getItemCount() {
return LENGTH;
}
}