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

时间:2011-09-09 10:51:16

标签: java sqlite

我在我的应用程序中收到此错误。我只是想知道这个错误exaclty意味着什么。如果你举一个简单的例子来解释

,那将是非常好的

3 个答案:

答案 0 :(得分:5)

它只是意味着您的Array或Cursor或者什么都没有任何元素,它的长度是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..

答案 1 :(得分:4)

您要求的是空数组的第一个元素。没有第一个元素,所以你得到一个例外。

答案 2 :(得分:2)

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

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和其他容器类中,但我不记得了。我希望你正在寻找的是什么。