0
내 mp3
및 wav
파일을 내 장치에 표시하려고합니다. 클릭하면 음악을 재생하기 위해 모든 벨소리의 경로를 mAudioPath[]
으로 저장하려고합니다. 나는이와 ListView
자원 문자열 배열을 얻을 :Android get managedQuery 커서 데이터 경로
private String[] getMusic() {
mCursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Media.DISPLAY_NAME},
Audio.Media.DATA + " like ? OR " + Audio.Media.DATA + " like ? ",
new String[] {"%mp3","%wav"},
"LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");
int count = mCursor.getCount();
String[] songs = new String[count];
int i = 0;
if (mCursor.moveToFirst()) {
do {
songs[i] = mCursor.getString(0);
mAudioPath[i] = mCursor.getString(mCursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
//--EXCEPTION--
i++;
} while (mCursor.moveToNext());
}
mCursor.close();
return songs;
}
그러나 라인 mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)
는 follewed 예외가 발생합니다 :
W/dalvikvm(14188): threadid=1: thread exiting with uncaught exception (group=0x4001d560)
E/AndroidRuntime(14188): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.Ringtones}: java.lang.IllegalArgumentException: column '_data' does not exist
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: column '_data' does not exist
at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
at com.example.myapp.Ringtones.getMusic(Ringtones.java:115)
at com.example.myapp.Ringtones.onCreate(Ringtones.java:73)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
어떻게에게
나는 이런 식으로 시도했지만 mAudioPath 초기화를 잊어 버렸습니다. D Tnx – Leo