我是新來的android。我正在使用服務實現音樂播放器。這裏是錯誤集中的代碼。任何人都可以幫我解決這個錯誤嗎?IllegalStateException:無法從CursorWindow讀取行0,列-1。確保光標在從其訪問數據前正確初始化
public void getSong() {
ContentResolver contentResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(musicUri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
do {
long thisId = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
String thisTitle = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String thisArtist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
int albumId = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART);
String thisArt = cursor.getString(albumId);
musicArrayList.add(new Music(thisId, thisTitle, thisArtist, thisArt));
} while (cursor.moveToNext());
}
}
您的錯誤爲空。確保你有足夠的媒體,以便遊標填滿。 –
是的,我檢查,它有足夠的媒體,所以光標不能爲空 – Janki
在哪一行是這個錯誤? –