尝试使用“moveToLast”到达最后一个光标位置sqlite DB 正在导致强制关闭
我可以打开我的数据库,没有明显的问题,
这段代码工作完美......
if (main.cursor.isLast()) {
main.cursor.moveToFirst();
} else {
main.cursor.moveToNext();
}
但是如果我尝试使用以下代码走另一条路,关闭我的数据库它会强制关闭......
try {
if ((main.cursor.isFirst()) || (main.cursor.isBeforeFirst())) {
main.cursor.moveToPosition((main.cursor.getCount()) - 1);
main.cursor.moveToPosition(lastrow);
} else {
main.cursor.moveToPrevious();
}
} catch (Exception e) {
e.printStackTrace();
}
我已经查看了所有的stackoverflow并在线尝试解决这个问题...
请帮忙!
编辑:Logcat
10-11 14:57:07.722: DEBUG/AndroidRuntime(450): Shutting down VM
10-11 14:57:07.722: WARN/dalvikvm(450): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-11 14:57:07.752: ERROR/AndroidRuntime(450): FATAL EXCEPTION: main
10-11 14:57:07.752: ERROR/AndroidRuntime(450): android.database.CursorIndexOutOfBoundsException: Index 185 requested, with a size of 185
10-11 14:57:07.752: ERROR/AndroidRuntime(450): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
10-11 14:57:07.752: ERROR/AndroidRuntime(450): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
10-11 14:57:07.752: ERROR/AndroidRuntime(450): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
I can open my Database with no apparent problem,
this piece of code works perfectly....
if (main.cursor.isLast()) {
main.cursor.moveToFirst();
} else {
main.cursor.moveToNext();
}
but if I try to go the other way with the following code, down my database it force closes...
try {
if ((main.cursor.isFirst()) || (main.cursor.isBeforeFirst())) {
main.cursor.moveToPosition((main.cursor.getCount()) - 1);
main.cursor.moveToPosition(lastrow);
} else {
main.cursor.moveToPrevious();
}
} catch (Exception e) {
e.printStackTrace();
}
I've looked all over stackoverflow and online trying to figure this out...
please help!
Edit: Logcat
10-11 14:57:07.722: DEBUG/AndroidRuntime(450): Shutting down VM
10-11 14:57:07.722: WARN/dalvikvm(450): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-11 14:57:07.752: ERROR/AndroidRuntime(450): FATAL EXCEPTION: main
10-11 14:57:07.752: ERROR/AndroidRuntime(450): android.database.CursorIndexOutOfBoundsException: Index 185 requested, with a size of 185
10-11 14:57:07.752: ERROR/AndroidRuntime(450): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
10-11 14:57:07.752: ERROR/AndroidRuntime(450): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
10-11 14:57:07.752: ERROR/AndroidRuntime(450): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 Logcat 显示错误:CursorIndexOutOfBoundsException:请求索引 185,大小为 185,这意味着您移动到错误的位置。
似乎这条线的原因是:
我认为那条线没有用。
Your Logcat show an error: CursorIndexOutOfBoundsException: Index 185 requested, with a size of 185, that mean you move to wrong position.
Seem that this line cause :
I think that line is useless.