-1

私は予算アプリケーションを持っており、SQLite データベースから情報を取得しようとしているときにIllegalStateExpeactionエラーが発生し続け、その理由がわかりません。これが私のコードMemos.add(i.getString(1));で、エラーが発生した行です

public List<String> getMemo(List<String> expeances) {
            // TODO Auto-generated method stub
            List<String> Memos = new ArrayList<String>();
            for(String exp: expeances)
            {
                Cursor i = ourDatabase.query(DATABASE_TABLE4, new String[]{KEY_MEMO},KEY_DATE+" = '"+exp+"'", null, null, null, null,null);

                if(i.getCount()>0)
                {
                    if(i.moveToFirst())
                    {
                        do 
                        {
                            Memos.add(i.getString(1));
                        } 
                        while (i.moveToNext());
                    }
                }
            }

            if (Memos.size()>0)
            {
                return Memos;
            }
            else
            {
                return null;
            }
        }

ここに私のlogcatがあります

 12-05 10:49:46.058: E/AndroidRuntime(12980): FATAL EXCEPTION: main
        12-05 10:49:46.058: E/AndroidRuntime(12980): java.lang.RuntimeException: Unable to start activity ComponentInfo{budget.app/budget.app.ReviewBudget}: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.os.Handler.dispatchMessage(Handler.java:99)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.os.Looper.loop(Looper.java:137)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.ActivityThread.main(ActivityThread.java:4745)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at java.lang.reflect.Method.invokeNative(Native Method)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at java.lang.reflect.Method.invoke(Method.java:511)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at dalvik.system.NativeStart.main(Native Method)
        12-05 10:49:46.058: E/AndroidRuntime(12980): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.database.CursorWindow.nativeGetString(Native Method)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.database.CursorWindow.getString(CursorWindow.java:434)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at budget.app.BudgetDB.getMemo(BudgetDB.java:511)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at budget.app.ReviewBudget.loadSpinnerData(ReviewBudget.java:58)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at budget.app.ReviewBudget.onCreate(ReviewBudget.java:51)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.Activity.performCreate(Activity.java:5008)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        12-05 10:49:46.058: E/AndroidRuntime(12980):    ... 11 more
4

2 に答える 2

3

カーソル プロジェクションには列が 1 つしかありませんKEY_MEMO

しかし、2番目の列にアクセスしようとしています

i.getString(1)

使用する

i.getString(0)

代わりは

于 2012-12-05T17:04:33.177 に答える
3

カーソルには1列しか含まれていません。

Memos.add(i.getString(0));
于 2012-12-05T17:05:04.843 に答える