Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “什么是”呢;“长度”;是否在ArrayIndexOutOfBoundsException中指定?_Java_Android - Fatal编程技术网

Java “什么是”呢;“长度”;是否在ArrayIndexOutOfBoundsException中指定?

Java “什么是”呢;“长度”;是否在ArrayIndexOutOfBoundsException中指定?,java,android,Java,Android,在执行我的Android代码时,我获得了以下格式的ArrayIndexOutOfBoundsException java.lang.ArrayIndexOutOfBoundsException: length=16; index=-1 只有当我在Android中获得ArrayIndexOutOfBoundsException时,这种格式才会出现。在Java中,我只是打印索引 我的问题是,在上面的陈述中,长度对我们意味着什么 它是ArrayList的容量还是ArrayList的大小?它代表数组的

在执行我的Android代码时,我获得了以下格式的
ArrayIndexOutOfBoundsException

java.lang.ArrayIndexOutOfBoundsException: length=16; index=-1
只有当我在Android中获得
ArrayIndexOutOfBoundsException
时,这种格式才会出现。在Java中,我只是打印索引

我的问题是,在上面的陈述中,长度对我们意味着什么


它是
ArrayList
的容量还是
ArrayList
的大小?

它代表数组的大小,即
16
,因此它从
0
15
。但是,您正在尝试访问位置
-1
中的元素,该位置当然不存在。

它代表数组的大小,即
16
,因此它从
0
15
。但是,您正在尝试访问位置
-1
中的元素,该位置当然不存在。

长度与ArrayList对象(当前存储在其中)中的元素数量相关。如果长度为n个元素,则长度从零变为n-1


希望有帮助:)

长度与ArrayList对象(当前存储在其中)中的元素数有关。如果长度为n个元素,则长度从零变为n-1

希望有帮助:)

java.lang.ArrayIndexOutOfBoundsException:长度=16;索引=-1

长度表示数组的大小
索引表示为其引发错误的非法索引

  • 数组的大小是16
  • 有效索引为0-15
  • 尝试访问的无效索引为“-1”
是ArrayList的容量还是ArrayList的大小

这是最重要的

大小表示该列表中元素的数量;然而,容量表示在ArrayList中可以容纳多少个元素,而无需重新分配其内部结构

java.lang.ArrayIndexOutOfBoundsException:长度=16;索引=-1

长度表示数组的大小
索引表示为其引发错误的非法索引

  • 数组的大小是16
  • 有效索引为0-15
  • 尝试访问的无效索引为“-1”
是ArrayList的容量还是ArrayList的大小

这是最重要的


大小表示该列表中元素的数量;然而,容量表示在ArrayList中可以容纳多少个元素,而无需重新分配其内部结构。

ArrayList的默认大小为16 so。ArrayList的默认大小为16 so。