Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
2018-02-26 20:56
1901 查看
尝试在一个空的对象引用上引用boolean java.util.List.add()这个方法;
错误例子:
private ArrayList<String> classList; classList.add("2014211501");相当于classList为null。
正确实例:
private ArrayList<String> classList=new ArrayList<String>(); classList.add("2014211501");
P.S.这个也算是一个比较典型的新手的错误了,NullPointException,一般有几种可能,也基本上都和没有初始化有关系。虽然没有在这里进行总结,但可以记录一下:
1.比较典型的是
int xxx;
然后报这个错;
直接修改成 int xxx=0;
2.还有一种,比如:
tv2=(TextView)findViewById(R.id.textView);
后面的R.id.textView写错了
3.再就是上面的这个了。好好看看吧骚年!
相关文章推荐
- Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayShowHomeEnabled(boolean)' on a null object reference
- Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference(Fb)
- Androd 解决Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null···
- java.lang.NullPointerException:Attempt to invoke virtual method xxx on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null objec
- java.lang.NullPointerException:TextView.setText(java.lang.CharSequence)' on a null object reference
- eclipse:The type java.lang.Object cannot be resolved. It is indirectly referenced from required
- ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
- Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null obj
- Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null objec
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- Eclipse error: The type java.lang.Object cannot be resolved. It is indirectly referenced from the required .class files
- The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- [Error!]the type java.lang.object cannot be resolved. it is indirectly reference
- Attempt to invoke virtual method 'void android.app.ActionBar.hide()' on a null object reference
- 安卓开发——报错:Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null