Java 请求的索引0的大小为0意味着什么?

Java 请求的索引0的大小为0意味着什么?,java,sqlite,Java,Sqlite,我的应用程序中出现了这个错误。我只是想知道这个错误究竟意味着什么。如果你能给出一个简单的例子来解释它,那就太好了。它只意味着你的数组或光标,或者什么东西没有任何元素,它的长度是0。所以 假定 String[] s = {};//not sure if it compiles. just an example for understanding s[0]//doing this means asking for 1st elemnt when s does't have any.. 您正在请求空

我的应用程序中出现了这个错误。我只是想知道这个错误究竟意味着什么。如果你能给出一个简单的例子来解释它,那就太好了。它只意味着你的数组或光标,或者什么东西没有任何元素,它的长度是0。所以

假定

String[] s = {};//not sure if it compiles. just an example for understanding
s[0]//doing this means asking for 1st elemnt when s does't have any..

您正在请求空数组的第一个元素。没有第一个元素,因此会出现异常。

在没有看到代码的情况下(这在这里非常有帮助),听起来好像有一个空数组或列表,而您要求的是第一个元素(它不存在)。例如:

String[] anArray = {"Hello", "world"}; //An array with two elements
System.out.println(anArray[0]); //prints "Hello".  anArray[0] gets the first element.

String[] anotherArray = {};  //An empty array.  There's nothing here to get.
System.out.println(anotherArray[0]);  //throws an exception because there's no first element to get.

我认为同样的事情可能会发生在
ArrayList
和其他容器类中,但我不记得了。我希望这正是您想要的。

您是如何得到错误的,请提供一些代码并详细说明您的问题。Google的第一个结果是。如果您得到的答案之一解决了您的问题,请单击复选标记接受它。