Null Pointer Android

0

When you run the application, this Adapter error appears:

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

So the error is in the getView method, and probably in that part:

view = inflater.inflate(R.layout.list_notice, null);

Can anyone help me?

My Adapter class :

public class NoticeAdapter extends BaseAdapter {

    private List<Notice> itemList;
    private LayoutInflater inflater;

    public NoticeAdapter(List<Notice> itemList, Context ctx) {
        this.itemList = itemList;
        inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        if (itemList != null)
            return itemList.size();
        return 0;
    }

    public Notice getItem(int position) {
        if (itemList != null)
            return itemList.get(position);
        return null;
    }

    public long getItemId(int position) {
        if (itemList != null)
            return itemList.get(position).hashCode();
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;

        if(view == null) {
            view = inflater.inflate(R.layout.list_notice, null);
            holder = new ViewHolder();
            view.setTag(holder);

            holder.tvId = (TextView) view.findViewById(R.id.title);
            holder.tvDesc = (TextView) view.findViewById(R.id.description);
            holder.tvPtime = (TextView) view.findViewById(R.id.publication_time);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tvId.setText(itemList.get(position).getTitle());
        holder.tvDesc.setText(itemList.get(position).getDescription());
        holder.tvPtime.setText(itemList.get(position).getPublicationTime());

        return view;
    }

    private static class ViewHolder {
        TextView tvId;
        TextView tvDesc;
        TextView tvPtime;
    }

    public List<Notice> getItemList() {
        return itemList;
    }

    public void setItemList(List<Notice> itemList) {
        this.itemList = itemList;
    }

}
    
asked by anonymous 29.05.2015 / 09:31

0 answers