Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference

问题原因:

1,int和Integer判断是否相等时出错

2,用到int的地方,实际传值是Integer

(int是基本类型,存数值;integer是对象,用一个引用指向这个对象)

解决方案:

对Integer参数进行null判断,如果不为null,再将Integer值转换成int

public Integer getResource(){
    return rid;
}

public void showImage(Integer resourceId){
    if(resourceId != null){
        Glide.with(context).load(resourceId.intValue());
    }
}
原文地址:https://www.cnblogs.com/ice5/p/14993681.html