NullPointerException in custom adapter getView
Change this:
vi = inflater.inflate(R.layout.result_list_item, null);
To this:
vi = inflater.inflate(R.layout.result_list_item, parent, false);
this is how your adapter should be:
public class NoPicAdapter extends ArrayAdapter<NewAndCalendar> {
private ArrayList<NewAndCalendar> data;
private Activity mActivity;
private LayoutInflater inflater = null;
public NoPicAdapter(Activity a, ArrayList<NewAndCalendar> d) {
super(a, R.layout.no_pic_list_item, d);
mActivity = a;
data = d;
inflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
View vi = convertView;
if (vi == null)
vi = inflater.inflate(R.layout.no_pic_list_item, parent, false);
TextView title = (TextView) vi.findViewById(R.id.noPicTitle);
TextView subtitle = (TextView) vi.findViewById(R.id.noPicSubtitle);
title.setText(data.get(position).getmTitle());
subtitle.setText(data.get(position).getmPubDate());
return vi;
}
}
Try this
vi = LayoutInflater.from(mActivity).inflate(R.layout.result_list_item, null);
if mActivity is your Activity context passed from the activity where you are creating the object of this adapter.