ArrayList#size() 多于实际的对象数 [英] ArrayList#size() is more than actual number of objects
问题描述
我的 Android 应用中有一个 ArrayList,其中有 2 个项目.然而,它的 size 方法返回 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
值的设置.右键单击调试器中的变量部分,然后选择 Customize Data Views...
.Hide null array elements
有一个选项,你应该确保没有勾选.
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屋!