开发者社区> 问答> 正文

关于读取Android虚拟机多媒体文件的问题?:报错

public class ViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
        ListView listview=(ListView)findViewById(R.layout.list);
        GetList getlist=new GetList();
        List<Map<String, Object>> fileInforList = getlist.MusicInfos(this.getContentResolver());
        SimpleAdapter adapter=new SimpleAdapter(this,fileInforList,R.layout.item,new String[]{"name","time"},new int[]{R.id.name,R.id.time});
        listview.setAdapter(adapter);
    }
public class GetList {
private String selection=MediaStore.Audio.Media.IS_MUSIC+"!=0";
private String[] projection={MediaStore.Audio.Media._ID,//歌曲ID
MediaStore.Audio.Media.TITLE,//歌曲标题
MediaStore.Audio.Media.ALBUM,//歌曲专辑
MediaStore.Audio.Media.ARTIST,//歌手
MediaStore.Audio.Media.DURATION,//播放时间
MediaStore.Audio.Media.SIZE,//文件大小
MediaStore.Audio.Media.DATA//文件路径
};
private Cursor cursor=null;
public List<Map<String,Object>> MusicInfos(ContentResolver cr)
{
cursor=cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
List<Map<String,Object>> listinfos=new ArrayList<Map<String,Object>>();
if(cursor==null)
{
return null;
}
else
{
while(cursor.moveToNext())
{
Map<String,Object> map=new HashMap<String,Object>();
map.put("name", cursor.getString(1));
map.put("album",cursor.getString(2));
map.put("singer",cursor.getString(3));
map.put("time", cursor.getString(4));
map.put("data", cursor.getString(6));
listinfos.add(map);
}
}
return listinfos;
}
}
}

运行时老是提示stopped unexpectedly ,麻烦各位看看这有什么问题?MP3的位置是这样吗?

展开
收起
kun坤 2020-06-07 22:07:21 506 0
1 条回答
写回答
取消 提交回答
  • 来人呐######泪奔啊!!!! ListView listview=(ListView)findViewById(R.layout.list);!!

    2020-06-07 22:07:26
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载