java.lang.NullPointerException:尝试调用虚方法' int java.util.ArrayList.size()'在null对象引用上

时间:2018-01-02 10:43:37

标签: java android

这是错误:java.lang.NullPointerException:尝试调用虚方法' int java.util.ArrayList.size()'在trainedge.alarmmanager.AlarmAdapter.getItemCount(AlarmAdapter.java:46)的null对象引用上

这是我收到错误的Adapter类

public class AlarmAdapter extends RecyclerView.Adapter<AlarmHolder> {

    Context context;

    public AlarmAdapter(Context context, ArrayList<Alarm> setItems) {
        this.context = context;
        this.setItems = setItems;
    }

    ArrayList<Alarm> setItems=new ArrayList();


    @Override
    public AlarmHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v= LayoutInflater.from(context).inflate(R.layout.simple_card_item,parent,false);
        return new AlarmHolder(v);
    }

    @Override
    public void onBindViewHolder(AlarmHolder holder, int position) {

        Alarm alarm=setItems.get(position);

        holder.tv_label.setText(alarm.getLabel());
        holder.tv_time.setText(alarm.getTine());

    }

    @Override
    public int getItemCount() {

        return setItems.size();
    }
}

这是模型

public class Alarm {
    public String label;
    public String tine;

    public Alarm() {
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getTine() {
        return tine;
    }

    public void setTine(String tine) {
        this.tine = tine;
    }

    public Alarm(String label, String tine) {

        this.label = label;
        this.tine = tine;
    }
}

0 个答案:

没有答案