[奇怪的问题]CursorIndexOutOfBoundsException:请求索引-1,大小为4
我有这段代码,用于在点击地图中的标记时显示 AlertDialog:
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
String[] result_columns = new String[] {COL_DESCRI};
Cursor cur = db.query(true, TABLE_COORD, result_columns,
null, null, null, null, null, null);
cur.moveToPosition(index-1);
String description = cur.getString(cur.getColumnIndexOrThrow(COL_DESCRI));
AlertDialog.Builder dialog = new AlertDialog.Builder(Geo.this);
dialog.setTitle("Infos.");
dialog.setMessage(description);
dialog.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
cur.close();
db.close();
return true;
}
问题是 4 个标记中的 3 个标记运行良好,缺点是有一个标记强制关闭应用程序。该错误可能是什么问题?我做了 cur.moveToPosition(index-1);
并且总是遇到同样的问题。 谢谢你的帮助。
I have this code to show an AlertDialog when taping on a marker in map:
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
String[] result_columns = new String[] {COL_DESCRI};
Cursor cur = db.query(true, TABLE_COORD, result_columns,
null, null, null, null, null, null);
cur.moveToPosition(index-1);
String description = cur.getString(cur.getColumnIndexOrThrow(COL_DESCRI));
AlertDialog.Builder dialog = new AlertDialog.Builder(Geo.this);
dialog.setTitle("Infos.");
dialog.setMessage(description);
dialog.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
cur.close();
db.close();
return true;
}
The problem is that 3 markers of 4 are well working, by cons, there is one that is force closes the application. What could be he problem of that error? I maked cur.moveToPosition(index-1);
and always the same problem.
Thanks for helping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用cur.moveToNext()?这对我有用
Did you try using
cur.moveToNext()
? It works for me