码迷,mamicode.com
首页 > 移动开发 > 详细

Attempt to invoke virtual method 'void com.loopj.android.image.SmartImageView.setImageUrl(java.lang.String, java.lang.Integer, java.lang.Integer)' on a null object reference

时间:2020-04-18 15:30:18      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:报错   ora   ring   使用   lan   poi   imageview   null   out   

使用ListView的适配器时报错:

java.lang.NullPointerException: Attempt to invoke virtual method ‘void com.loopj.android.image.SmartImageView.setImageUrl(java.lang.String, java.lang.Integer, java.lang.Integer)‘ on a null object reference

出错代码:

1 View view1 = View.inflate(MainActivity.this, R.layout.news_item, null);
2 SmartImageView siv_icon = findViewById(R.id.siv_icon);
3 TextView tv_title = findViewById(R.id.tv_title);
4 TextView tv_description = findViewById(R.id.tv_description);
5 TextView tv_type = findViewById(R.id.tv_type);

 

正确代码:

1 View view1 = View.inflate(MainActivity.this, R.layout.news_item, null);
2 SmartImageView siv_icon = view1.findViewById(R.id.siv_icon);
3 TextView tv_title = view1.findViewById(R.id.tv_title);
4 TextView tv_description = view1.findViewById(R.id.tv_description);
5 TextView tv_type = view1.findViewById(R.id.tv_type);
6     

虽然第一种代码在编译器里并不会报错,但是在app开启时就会发生闪退

 


       

Attempt to invoke virtual method 'void com.loopj.android.image.SmartImageView.setImageUrl(java.lang.String, java.lang.Integer, java.lang.Integer)' on a null object reference

标签:报错   ora   ring   使用   lan   poi   imageview   null   out   

原文地址:https://www.cnblogs.com/y-yang/p/12725934.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!