Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SQLite数据库游标迭代错误_Android_Sqlite_Cursor - Fatal编程技术网

Android SQLite数据库游标迭代错误

Android SQLite数据库游标迭代错误,android,sqlite,cursor,Android,Sqlite,Cursor,我有一个SQLite数据库,当我尝试循环遍历所有记录时,我在迭代过程中得到一个错误。我在这个数据库中有大约900条记录,当它到达记录217时,I整数到达217,出于调试目的,我从CursorWindow标记中得到一个错误,声明: 无法从包含0行7列的游标窗口中读取第0行第1列 以下是通过记录进行迭代的代码: String selectQuery = "SELECT * FROM " + SONG_TABLE_NAME; Cursor c = null; try { SQLiteDatab

我有一个SQLite数据库,当我尝试循环遍历所有记录时,我在迭代过程中得到一个错误。我在这个数据库中有大约900条记录,当它到达记录217时,I整数到达217,出于调试目的,我从CursorWindow标记中得到一个错误,声明:

无法从包含0行7列的游标窗口中读取第0行第1列

以下是通过记录进行迭代的代码:

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时出错。这是相关的日志

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

你能在IDS210-220上发布完整的日志和数据吗。这将有助于我们相互联系,刚刚意识到它在218上出错,因为我设置了I=1而不是0,就像在最初的帖子中一样。所以它仍然在同一地点出错。请添加您的FutureTask,java也在其中指明第355行。例外是FutureTask在java.util中,这不是我的代码。但异步任务失败的原因是,获取试图检索记录编号218的游标失败。它也不是记录218中的数据,因为我删除了文件210-220,然后重试,仍然在相同的位置得到错误。post SongsDatabase.java并指示行号225