首页> 开发问题 >其它问题 其它问题
Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
作者:小萝卜 2019-11-30 【 漏洞BUG 】 浏览 3296
简介Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
尝试在一个空的对象引用上引用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.再就是上面的这个了。好好看看吧骚年!
很赞哦! (0)
相关文章
- Python运行语法错误:IndentationError: unindent does not match any outer indentation level
- datagrid MAC和VPNIP显示不出来,Time显示错误的问题
- module 'torch' has no attribute 'gesv'
- scp 文件 : /目录: Permission denied
- Java compiler level does not match the version of the installed Java project facet
- TypeError: 'newline' is an invalid keyword argument for this function 错误解决
- bash: hadoop:command not found
- VMWARE虚拟机安装64位系统此主机支持IntelVTx 但IntelVTx处于禁用状态
- Namenode 没启动
- clion ctrl+鼠标左键不能调到函数实现
