ArrayList#size()超过实际的对象数 [英] ArrayList#size() is more than actual number of objects
问题描述
我的Android应用程序中有一个ArrayList,它有2个项目。然而,它的大小方法返回3.我知道它听起来真的很简单和愚蠢,但这是如何:
I have an ArrayList in my Android app, and it has 2 items in it. However, its size method returns 3. I know it sounds really simply and stupid, but here is how it goes:
为什么会发生这种情况? ArrayList的大小如何返回错误的数字?当我迭代列表时,这会导致空指针异常。
Why would this happen? How can an ArrayList's size return an incorrect number? This causes a null pointer exception when I'm iterating the list.
推荐答案
IntelliJ有关于隐藏 null
值。右键单击调试器中的变量部分,然后选择自定义数据视图...
。 隐藏空数组元素
有一个选项,你应该确保它是未被选中的。
IntelliJ has a setting about hiding null
values. Right click the variables section in the debugger and choose Customize Data Views...
. There is an option there for Hide null array elements
that you should make sure is unticked.
这篇关于ArrayList#size()超过实际的对象数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!