Android SQLite数据库游标迭代错误

时间:2014-03-24 16:34:14

标签: android sqlite cursor

我有一个SQLite数据库,当我尝试遍历所有记录时,我在迭代期间收到错误。我在这个数据库中有大约900条记录,当它到达记录217时,(i整数变为217,出于调试目的)我从CursorWindow标记中得到一个错误说明:

“无法从CursorWindow中读取第0行第1列,其中包含0行,7列。”

以下是迭代记录的代码:

String selectQuery = "SELECT * FROM " + SONG_TABLE_NAME;
Cursor c = null;
try {
    SQLiteDatabase db = this.getReadableDatabase();
    c = db.rawQuery(selectQuery, null);

    //loop through all rows and add to list
    if (c!= null) {
        c.moveToFirst();
        int i = 0;
        do {
            System.out.println(i);
            i++;

            //Do stuff...

          } while (c.moveToNext());
      }
  } finally {
      if (c != null)
          c.close();
  }

谢谢。

更新: 数据是关于歌曲信息的。歌曲名称,艺术家,专辑存储为字符串。专辑艺术存储为字节数组(blob在数据库中)。

songNo=210 albumName=Long Live the Kings songName=Proud To Be A Stoner artistName=Kottonmouth Kings art=[B@42236c50
songNo=211 albumName=Koast II Koast songName=Party artistName=Kottonmouth Kings art=[B@422ae498
songNo=212 albumName=Koast II Koast songName=Where's the Weed At artistName=Kottonmouth Kings art=[B@4231ac18
songNo=213 albumName=High Society songName=First Class artistName=Kottonmouth Kings art=[B@422ae498
songNo=214 albumName=Cloud Nine songName=Pass It Around artistName=Kottonmouth Kings art=[B@422d7be8
songNo=215 albumName=Rollin' Stoned songName=Rest of My Life artistName=Kottonmouth Kings art=[B@423451c0
songNo=216 albumName=Rollin' Stoned songName=Tangerine Sky artistName=Kottonmouth Kings art=[B@42378ef8
songNo=217 albumName=Hidden Stash III [Disc 1] songName=Still Smokin artistName=Kottonmouth Kings art=[B@423acc30
songNo=218 albumName=Get Buck in Here songName=Get Buck in Here artistName=DJ Felli Fel art=[B@422ae498
songNo=219 albumName=Best Day Ever songName=Get Up! artistName=Mac Miller art=[B@422f3138
songNo=220 albumName=K.I.D.S songName=Knock Knock artistName=Mac Miller art=[B@4231ba98

现在,当我运行它时,我在获取记录218时出错。这是相关的logcat。

03-24 12:57:22.799: I/System.out(15710): 210
03-24 12:57:22.809: D/dalvikvm(15710): GC_FOR_ALLOC freed 497K, 17% free 9941K/11928K, paused 14ms, total 15ms
03-24 12:57:22.809: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:22.809: I/System.out(15710): 211
03-24 12:57:22.829: D/dalvikvm(15710): GC_FOR_ALLOC freed 236K, 17% free 9941K/11928K, paused 15ms, total 15ms
03-24 12:57:22.839: D/dalvikvm(15710): GC_FOR_ALLOC freed 478K, 17% free 9941K/11928K, paused 15ms, total 15ms
03-24 12:57:22.839: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:22.919: W/CursorWindow(15710): Window is full: requested allocation 169783 bytes, free space 72617 bytes, window size 2097152 bytes
03-24 12:57:22.919: I/System.out(15710): 212
03-24 12:57:22.929: D/dalvikvm(15710): GC_FOR_ALLOC freed 478K, 17% free 9941K/11928K, paused 14ms, total 14ms
03-24 12:57:22.949: D/dalvikvm(15710): GC_FOR_ALLOC freed 433K, 17% free 9941K/11928K, paused 14ms, total 14ms
03-24 12:57:22.949: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:22.949: I/System.out(15710): 213
03-24 12:57:22.959: D/dalvikvm(15710): GC_FOR_ALLOC freed 434K, 17% free 9942K/11928K, paused 14ms, total 14ms
03-24 12:57:22.979: D/dalvikvm(15710): GC_FOR_ALLOC freed 448K, 17% free 9942K/11928K, paused 14ms, total 14ms
03-24 12:57:22.979: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:23.049: W/CursorWindow(15710): Window is full: requested allocation 447936 bytes, free space 172276 bytes, window size 2097152 bytes
03-24 12:57:23.049: I/System.out(15710): 214
03-24 12:57:23.069: D/dalvikvm(15710): GC_FOR_ALLOC freed 449K, 17% free 9942K/11928K, paused 14ms, total 14ms
03-24 12:57:23.069: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:23.139: W/CursorWindow(15710): Window is full: requested allocation 447936 bytes, free space 411808 bytes, window size 2097152 bytes
03-24 12:57:23.159: W/CursorWindow(15710): Window is full: requested allocation 2974082 bytes, free space 1223747 bytes, window size 2097152 bytes
03-24 12:57:41.767: I/System.out(15710): record number: 215215
03-24 12:57:44.460: D/dalvikvm(15710): GC_FOR_ALLOC freed 332K, 17% free 9942K/11928K, paused 25ms, total 26ms
03-24 12:57:46.342: D/dalvikvm(15710): GC_FOR_ALLOC freed 437K, 17% free 9942K/11928K, paused 25ms, total 26ms
03-24 12:57:46.572: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:48.224: I/System.out(15710): 216
03-24 12:57:52.478: D/dalvikvm(15710): GC_FOR_ALLOC freed 437K, 17% free 9943K/11928K, paused 24ms, total 25ms
03-24 12:57:54.290: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:57:57.333: I/System.out(15710): 217
03-24 12:58:05.340: D/dalvikvm(15710): GC_FOR_ALLOC freed 415K, 17% free 9943K/11928K, paused 24ms, total 25ms
03-24 12:58:08.363: D/skia(15710): --- SkImageDecoder::Factory returned null
03-24 12:58:12.087: W/CursorWindow(15710): Window is full: requested allocation 2974082 bytes, free space 594167 bytes, window size 2097152 bytes
03-24 12:58:12.087: W/CursorWindow(15710): Window is full: requested allocation 2974082 bytes, free space 2096591 bytes, window size 2097152 bytes
03-24 12:58:13.338: I/System.out(15710): 218
03-24 12:58:15.120: E/CursorWindow(15710): Failed to read row 0, column 1 from a CursorWindow which has 0 rows, 7 columns.
03-24 12:58:16.772: E/CursorWindow(15710): Failed to read row 0, column 3 from a CursorWindow which has 0 rows, 7 columns.
03-24 12:58:24.679: E/CursorWindow(15710): Failed to read row 0, column 2 from a CursorWindow which has 0 rows, 7 columns.
03-24 12:59:15.048: E/CursorWindow(15710): Failed to read row 0, column 6 from a CursorWindow which has 0 rows, 7 columns.
03-24 12:59:16.390: E/CursorWindow(15710): Failed to read row 0, column 5 from a CursorWindow which has 0 rows, 7 columns.
03-24 12:59:40.583: W/dalvikvm(15710): threadid=11: thread exiting with uncaught exception (group=0x4189cba8)
03-24 12:59:40.663: E/AndroidRuntime(15710): FATAL EXCEPTION: AsyncTask #1
03-24 12:59:40.663: E/AndroidRuntime(15710): Process: com.allengauch.mediaplayer, PID: 15710
03-24 12:59:40.663: E/AndroidRuntime(15710): java.lang.RuntimeException: An error occured while executing doInBackground()
03-24 12:59:40.663: E/AndroidRuntime(15710): at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-24 12:59:40.663: E/AndroidRuntime(15710): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.lang.Thread.run(Thread.java:841)
03-24 12:59:40.663: E/AndroidRuntime(15710): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 5 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
03-24 12:59:40.663: E/AndroidRuntime(15710): at android.database.CursorWindow.nativeGetBlob(Native Method)
03-24 12:59:40.663: E/AndroidRuntime(15710): at android.database.CursorWindow.getBlob(CursorWindow.java:399) 
03-24 12:59:40.663: E/AndroidRuntime(15710): at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:45)
03-24 12:59:40.663: E/AndroidRuntime(15710): at com.allengauch.mediaplayer.SongsDataBase.getAllSongs(SongsDataBase.java:225) 
03-24 12:59:40.663: E/AndroidRuntime(15710): at com.allengauch.mediaplayer.SongsActivity$WorkerThread.doInBackground(SongsActivity.java:252)
03-24 12:59:40.663: E/AndroidRuntime(15710): at com.allengauch.mediaplayer.SongsActivity$WorkerThread.doInBackground(SongsActivity.java:1) 
03-24 12:59:40.663: E/AndroidRuntime(15710): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-24 12:59:40.663: E/AndroidRuntime(15710): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-24 12:59:40.663: E/AndroidRuntime(15710): ... 4 more

0 个答案:

没有答案