0
我試圖從SD卡在手機上添加的歌曲名稱列表視圖,但我得到一個空指針異常......Android的ListView控件添加到列表
private void updateList() {
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Artists.ARTIST };
Cursor tempCursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj,
null,
null,
null);
int col_index = -1;
int numSongs = tempCursor.getCount();
while (tempCursor.moveToNext()) {
col_index = tempCursor.getColumnIndexOrThrow(
MediaStore.Audio.Artists.ARTIST);
songname.add(tempCursor.getString(col_index));
}
ArrayAdapter<String> songss = new ArrayAdapter<String>(
this, R.id.songs, songname);
setListAdapter(songss);
}
*您在哪裏*得到例外?什麼是'songname',它在哪裏初始化? –