本文介绍了CursorIndexOutOfBoundsException问题:指数4要求,为4的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示每个厂商的AlertDialog,有一些说明,因为这,我使用这个code:

I want to display for each maker an AlertDialog that has some description, for that, i'm using this code:

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);
                String description = cur.getString(cur.getColumnIndexOrThrow("description"));

                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.moveToNext();

             cur.close();
             db.close();

            return true;
        }

的问题,有一些标记的alertdialog结果是正确的,有一些人,当我点击它,我有一个FC。logcat的:

The problem that there is some markers that the alertdialog result is correct, and there is some others that when i tap on it i have a FC.Logcat:

08-23 17:41:37.531: ERROR/AndroidRuntime(10004): Uncaught handler: thread main exiting due to uncaught exception
08-23 17:41:37.550: ERROR/AndroidRuntime(10004): android.database.CursorIndexOutOfBoundsException: Index 4 requested, with a size of 4
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at carburant.android.com.Geo$ItemizedOverlayPerso.onTap(Geo.java:244)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:628)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.View.dispatchTouchEvent(View.java:3709)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.os.Looper.loop(Looper.java:123)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at android.app.ActivityThread.main(ActivityThread.java:4363)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at java.lang.reflect.Method.invokeNative(Native Method)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at java.lang.reflect.Method.invoke(Method.java:521)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-23 17:41:37.550: ERROR/AndroidRuntime(10004):     at dalvik.system.NativeStart.main(Native Method)

当我把 cur.moveToPosition(指数); 字符串描述= cur.getString(cur.getColumnIndexOrThrow(说明)); 指数-1要求,具有4大小否则,像上面code 指数4要求,与4的大小

When i put cur.moveToPosition(index); under String description = cur.getString(cur.getColumnIndexOrThrow("description")); i have Index -1 requested, with a size of 4 otherwise, like above code Index 4 requested, with a size of 4

推荐答案

数组索引开始 0 ,不是 1 。你的第四个元素存储在索引 3

Array indexing starts with 0, not 1. your fourth element is stored at index 3.

当我把cur.moveToPosition(指数);在字符串描述= cur.getString(cur.getColumnIndexOrThrow(说明));我已经索引-1要求,具有4大小,否则,像上面code指数4要求,为4的尺寸

在该行集首先返回光标将在当前位置-1,这是第一行之前。

When the row set is first returned the cursor will be at positon -1, which is before the first row.

这篇关于CursorIndexOutOfBoundsException问题:指数4要求,为4的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 06:12