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());
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM