0
public void getSongList() {
//retrieve song info
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
int dataColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.DATA);
int artColumn=musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Albums.ALBUM_ART);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisData = musicCursor.getString(dataColumn);
String thisArt = musicCursor.getString(artColumn);
File imgFile=new File(thisArt);
if(imgFile.exists()){
albumArt= BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}
songList.add(new Song(thisId, thisTitle, thisArtist,thisData,albumArt));
}
while (musicCursor.moveToNext());
musicCursor.close();
}
}
치명적인 예외 보여주고있다 :내가 모든 노래의 앨범 아트를 얻기 위해 노력하고 있지만, 다음과 같은 런타임 오류를
Process: com.example.kishan.experimentonmusicplayer, PID: 3373
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kishan.experimentonmusicplayer/com.example.kishan.experimentonmusicplayer.MainActivity}: 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:2584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
주에 의한 : java.lang.IllegalStateException를 : 행을 읽을 수 없습니다 0, col -1 (CursorWindow에서) 커서가 데이터에 액세스하기 전에 커서가 올바르게 초기화되었는지 확인하십시오.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:66)
at android.database.CursorWrapper.getString(CursorWrapper.java:137)
at com.example.kishan.experimentonmusicplayer.MainActivity.getSongList(MainActivity.java:161)
at com.example.kishan.experimentonmusicplayer.MainActivity.onCreate(MainActivity.java:81)
at android.app.Activity.performCreate(Activity.java:6583)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2531)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)