Vla*_*dys 0 java arraylist nullpointerexception
在一些转换ArrayList有3个元素后,ArrayList大小最大然后是3.因此NullPointerException在使用forEachcircle 时会发生.
如何避免这种情况?我的意思是不!=null检查.
例:
List<String> busesIdToRemove = driverWrapper.getBusesIdToRemove();
Run Code Online (Sandbox Code Playgroud)
列表包含id的那些实体,将被删除.发生错误:
for (String id : busesIdToRemove) {
Long longId = Long.valueOf(id); //here. Because id is null ...
}
Run Code Online (Sandbox Code Playgroud)
但实际上,list只包含非空值的元素.
例如[index,value].
1,"41";
4,"50"......
有关索引[0],[2],[3]的元素的信息在调试器中不存在,并且对于get(0)例如方法返回null .
解决问题:arrayList.removeAll(Collections.singleton(null));
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |