【问题标题】:[Weird problem]CursorIndexOutOfBoundsException: Index -1 requested, with a size of 4[奇怪的问题]CursorIndexOutOfBoundsException: Index -1 requested, with a size of 4
【发布时间】:2011-08-24 01:09:02
【问题描述】:

我有这段代码可以在点击地图中的标记时显示 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); 并且总是同样的问题。 感谢您的帮助。

【问题讨论】:

    标签: android sqlite google-maps google-maps-markers android-alertdialog


    【解决方案1】:

    您是否尝试过使用cur.moveToNext()?它对我有用

    【讨论】:

    • 我必须让它循环,如果我这样做,当我点击一个标记时,我将显示所有的警报对话框。
    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 2017-04-09
    • 2021-12-17
    • 1970-01-01
    • 2021-10-02
    • 2011-07-22
    • 1970-01-01
    • 2020-03-01
    相关资源
    最近更新 更多