Attempt to invoke virtual method 'void com.loopj.android.image.SmartImageView.setImageUrl(java.l

曾无好事来相访,赖尔高文一起予。这篇文章主要讲述Attempt to invoke virtual method ' void com.loopj.android.image.SmartImageView.setImageUrl(java.l相关的知识,希望能为你提供帮助。
使用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

【Attempt to invoke virtual method ' void com.loopj.android.image.SmartImageView.setImageUrl(java.l】虽然第一种代码在编译器里并不会报错,但是在app开启时就会发生闪退
 

             

    推荐阅读