android - APK 适用于三星,但在 Nexus 中出现 2 个错误?

标签 android android-studio

在我的应用程序中,首先创建一个 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 并不总是有外部存储,但为了更准确,您应该检查跟踪错误,很可能您能够看到导致运行时错误的确切行

关于android - APK 适用于三星,但在 Nexus 中出现 2 个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43667448/

相关文章:

android - 如何使用 ArrayList 动态更新微调器?

android - 在 PreLollipop 设备中看不到 RelativeLayout 中的 View /布局

java - 在抽屉导航 Activity 中显示获取的个人资料图片

安卓工作室 : How to find latest version number of google specific libraries?

android - 未找到已安装的构建工具。安装 Android 构建工具 30.0 版

android - 如何将 Android Studio 中的终端更改为 iTerm2?

android - 无法从 Android 中的蓝牙设备读取任何数据

android - ExpandableListView 中的 groupPosition 给了我错误的值

java - 可点击的 ListView

android - Android Studio 中的两个模块使用相同的库