APK在三星上工作,但在Nexus中给出了2个错误



在我的应用程序中,首先创建一个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)

也许只是这一行错误

File file = new File(Environment.getExternalStorageDirectory(), newFolder);

nexus并不总是有外部存储,但是要更准确,您应该检查跟踪错误,很可能您可以看到导致Runt Time错误的精确行

最新更新