在我的应用程序中,首先创建一个NewFolder,然后我录制音频并将它们保存在这个新文件夹中。
我还有一个ArrayList来显示我的记录
这里我创建了NewFolder
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
String sep = File.separator; // Use this instead of hardcoding the "/"
String newFolder = "FolderName";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + sep + newFolder);
//myNewFolder.mkdir();
myNewFolder.mkdirs();
while (fs.getfetchstatus() != true) {
mySongs = fs.findSongs(Environment.getExternalStorageDirectory());
//>>>>>>>>>>HERE IS HAVING ANY ERROR<<<<<<<<<
}
if (mySongs != null) {
dialog.dismiss();
}
mySongs = fs.getsonglist();
items = new String[mySongs.size()];
for (int i = 0; i < mySongs.size(); i++) {
items[i] = mySongs.get(i).getName().toString().replace(".3gp", "");
}
final ArrayAdapter<String> adp = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, items);
adp.notifyDataSetChanged();
lv.setAdapter(adp);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getApplicationContext(), Player.class);
intent.putExtra("pos", i);
adp.notifyDataSetChanged();
startActivity(intent);
finish();
}
});
这是我的ArrayList
boolean fetchstatus=false;
ArrayList<File> songs=new ArrayList<File>();
String sep = File.separator; // Use this instead of hardcoding the "/"
String newFolder = "FolderName";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + sep + newFolder);
//File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
FetchSongs(){
}
public ArrayList<File> findSongs(File root){
ArrayList<File> al=new ArrayList<File>();
// File[] files=root.listFiles();
//File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(Environment.getExternalStorageDirectory(), newFolder);
File[] files = file.listFiles();
for (File singleFile : files){
if(singleFile.isDirectory() && !singleFile.isHidden()){
al.addAll(findSongs(singleFile));
//>>>>>>>ERROR HERE<<<<<<<<<<<<<<<<<<<
}
else {
if(singleFile.getName().endsWith(".mp3")){
al.add(singleFile);
}
}
}
fetchstatus=true;
songs=al;
return al;
}
我有这些错误
java.lang.RuntimeException: Unable to start activity ComponentInfo
at org.usr.usr.musicplayer.FetchSongs.findSongs(FetchSongs.java:35)
at org.usr.usr.musicplayer.MainActivity.onCreate(MainActivity.java:124)
答案 0 :(得分:1)
也许只是这一行的错误
File file = new File(Environment.getExternalStorageDirectory(), newFolder);
Nexus并不总是有外部存储空间,但为了更准确,您应该检查跟踪错误,很可能您将能够看到导致欠幅错误时间错误的确切行