Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 音乐的列表路径_Android_File_Path - Fatal编程技术网

Android 音乐的列表路径

Android 音乐的列表路径,android,file,path,Android,File,Path,我想创建一个歌曲列表和他的路径。我写了这段代码,但是当我尝试创建列表时,应用程序崩溃了。从文件中获取列表时出错。我怎样才能找到我歌曲的路径 File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); Toast.makeText(this, f.toString(), Toast.LENGTH_LONG).show(); if (f.listFiles().length >

我想创建一个歌曲列表和他的路径。我写了这段代码,但是当我尝试创建列表时,应用程序崩溃了。从文件中获取列表时出错。我怎样才能找到我歌曲的路径

File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);

Toast.makeText(this, f.toString(), Toast.LENGTH_LONG).show();



if (f.listFiles().length > 0) {
    for (File file : f.listFiles(new FileExtensionFilter())) {
        Map<String, String> song = new HashMap<String, String>();
        song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
        song.put("songPath", file.getPath());

        songsList.add(song);
        Toast.makeText(this, song.toString(), Toast.LENGTH_LONG).show();
    }
}
文件f=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\u MUSIC);
Toast.makeText(this,f.toString(),Toast.LENGTH_LONG).show();
如果(f.listFiles().length>0){
对于(文件:f.listFiles(新文件扩展筛选器())){
Map song=newhashmap();
song.put(“songTitle”,file.getName().substring(0,(file.getName().length()-4));
put(“songPath”,file.getPath());
歌曲列表。添加(歌曲);
Toast.makeText(this,song.toString(),Toast.LENGTH_LONG).show();
}
}
请发布您的日志(错误列表),否则我们将无法帮助您。f.listFiles()为空,我不知道为什么