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

Posted y-yang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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     

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

 


       

以上是关于Attempt to invoke virtual method 'void com.loopj.android.image.SmartImageView.setImageUrl(java.l的主要内容,如果未能解决你的问题,请参考以下文章

Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setHomeButtonEnabled(boo

java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.yunweather.

java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.database.sqlite异常(代码片段

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

Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a nu

Android报错提示Attempt to invoke interface method ‘int java.util.List.size()‘ on a null object reference