Android android.database.CursorIndexOutOfBoundsException:请求索引 2,大小为 2
我有这个日志
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): FATAL EXCEPTION: main 07-27 21:42:05.635:错误/AndroidRuntime(26094):android.database.CursorIndexOutOfBoundsException:请求索引2,大小为2 07-27 21:42:05.635:错误/AndroidRuntime(26094):在android.database.AbstractCursor.checkPosition(AbstractCursor.java:580) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在it.android.infoconsumatori.ServiceS $ 1.handleMessage(ServiceS.java:101) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在android.os.Handler.dispatchMessage(Handler.java:99) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在android.os.Looper.loop(Looper.java:123) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在android.app.ActivityThread.main(ActivityThread.java:3691) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在java.lang.reflect.Method.invokeNative(本机方法) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在java.lang.reflect.Method.invoke(Method.java:507) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:847) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 07-27 21:42:05.635:错误/AndroidRuntime(26094):在dalvik.system.NativeStart.main(本机方法) 07-27 21:42:05.640:错误/(2695):转储状态> /data/log/dumpstate_app_error
有什么问题?
I have this log
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): FATAL EXCEPTION: main
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): android.database.CursorIndexOutOfBoundsException: Index 2 requested, with a size of 2
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at it.android.infoconsumatori.ServiceS$1.handleMessage(ServiceS.java:101)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at android.os.Looper.loop(Looper.java:123)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at android.app.ActivityThread.main(ActivityThread.java:3691)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at java.lang.reflect.Method.invoke(Method.java:507)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
07-27 21:42:05.635: ERROR/AndroidRuntime(26094): at dalvik.system.NativeStart.main(Native Method)
07-27 21:42:05.640: ERROR/(2695): Dumpstate > /data/log/dumpstate_app_error
What is the problem ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着您正在访问一个不存在的项目。可以这样想:游标有一定数量的行(您要访问的数据),这些行是零索引的,这意味着如果有 10 行数据,则第一行数据是索引0,第 10 行(最后一个可用值)是索引 9,而不是索引 10 - 索引 10 不存在。
你的问题正是由于这个原因,你有一个两行的游标(索引0到1),并且你试图访问索引2(根本不存在的第三个项目),因此你会抛出异常。
希望有帮助。
That means you are accessing an item that does not exist. Think of it like this: A cursor has a certain number of rows (the data you want to access), these rows are Zero-indexed, meaning that if there are 10 rows of data, the first row of data is Index 0, and the 10th row (the last available value) is Index 9 not Index 10 - Index 10 does not exist.
Your problem is exactly due to this, you have a cursor of two rows (index 0 through 1), and you are attempting to access index 2 (a third item that simply isn't there), therefore you get an exception thrown.
Hope that helped.