游标未正确初始化SQLite Database Android

时间:2018-07-31 09:55:51

标签: java android database sqlite exception

我正在尝试使用以下代码从android中的SQLite数据库获取所有数据。运行它时,它崩溃并给我这个异常->

java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery("SELECT * FROM " + menuItemTable,null);

    if(c.moveToFirst() && c != null){
        do{
            Log.d("Log->", c.getString(c.getColumnIndex(TitleField)));
        }while(c.moveToNext());
    }
    db.close();

有人可以帮我吗?谢谢!

其余的堆栈跟踪

07-31 13:12:49.919 19572-19572/tnstudio.android.ubb_application E/CursorWindow: Failed to read row 0, column 1 from a CursorWindow which has 0 rows, 7 columns.
07-31 13:12:49.920 19572-19572/tnstudio.android.ubb_application E/AndroidRuntime: FATAL EXCEPTION: main
    Process: tnstudio.android.ubb_application, PID: 19572
    java.lang.RuntimeException: Unable to start activity ComponentInfo{tnstudio.android.ubb_application/tnstudio.android.ubb_application.UBBNewsActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5349)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
     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.
        at android.database.CursorWindow.nativeGetString(Native Method)
        at android.database.CursorWindow.getString(CursorWindow.java:438)
        at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
        at tnstudio.android.ubb_application.DatabaseHelper.getFeedItems(DatabaseHelper.java:95)
        at tnstudio.android.ubb_application.UBBNewsActivity.onCreate(UBBNewsActivity.java:57)
        at android.app.Activity.performCreate(Activity.java:6020)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5349) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 

0 个答案:

没有答案