codekidX / storage-chooser

Lets user choose files in internal or external storage with just few lines of code.
Mozilla Public License 2.0
719 stars 153 forks source link

StringIndexOutOfBoundsException at com.codekidlabs.storagechooser.fragments.SecondaryChooserFragment.populateList(SecondaryChooserFragment.java:623) #104

Open yhs0602 opened 5 years ago

yhs0602 commented 5 years ago

https://github.com/KYHSGeekCode/Android-Disassembler/issues/47

Well, it is said that StringIndexOutOfBoundsException is occuring from your code.

My code is here like this.

private void showFileChooser()
{
    requestAppPermissions(this);
    //SharedPreferences sharedPreferences = null;
    settingPath=getSharedPreferences("path",MODE_PRIVATE);
    String prepath=settingPath.getString(DiskUtil.SC_PREFERENCE_KEY,"/storage/emulated/0/");
    File tmp=new File(prepath);
    if(tmp.isFile())
    {
        tmp=tmp.getParentFile();
        prepath=tmp.getAbsolutePath();
    }
    SharedPreferences spPicker=getSharedPreferences(SETTINGKEY,MODE_PRIVATE);
    int picker=spPicker.getInt("Picker",0);
    switch(picker)
    {
        case 0:
            StorageChooser chooser = new StorageChooser.Builder()
                .withActivity(MainActivity.this)
                .withFragmentManager(getFragmentManager())
                .withMemoryBar(true)
                .allowCustomPath(true)
                .setType(StorageChooser.FILE_PICKER)
                .actionSave(true)       
                //.withPreference(settingPath)
            //  .withPredefinedPath(prepath)
                .shouldResumeSession(true)
                .showHidden(true)
                .build();
                // Show dialog whenever you want by
            //chooser.getsConfig().setPrimaryPath(prepath);
            chooser.show();
            // get path that the user has chosen
            chooser.setOnSelectListener(new StorageChooser.OnSelectListener() {
                    @Override
                    public void onSelect(String path) {
                        SharedPreferences.Editor edi=settingPath.edit();
                        edi.putString(DiskUtil.SC_PREFERENCE_KEY,path);
                        edi.apply();
                        disableEnableControls(false,llmainLinearLayoutSetupRaw);
                        OnChoosePath(path);
                        //Log.e("SELECTED_PATH", path);
                    }
                });
            break;
        case 1:
            Intent i=new Intent(this, com.kyhsgeekcode.rootpicker.FileSelectorActivity.class);
            startActivityForResult(i, REQUEST_SELECT_FILE);     
            break;
    }   //  
}
codekidX commented 5 years ago

Hi, thanks for letting me know. I have got this weird bug sometimes but I couldn't spot the error as the next time it would work. The dev-3.0 branch is now rewritten in Kotlin and has a fresh codebase so I hope this won't come in the next release as well.

I'm not closing this issue until 3.0.

rahulpopuri commented 5 years ago

+1 My users are reporting this issue too

Until this is fixed, should I just be catching the StringIndexOutOfBoundsException and retrying?

muzzikapp commented 5 years ago

Fixed in my fork branch, basicly what i do is if i got an exception i set the selected folder to default music folder (at least app doesnt crash because of this)

https://github.com/muzzikapp/storage-chooser

codekidX commented 5 years ago

@muzzikapp thanks for this. Was there any reason why you weren't able to create PR?

muzzikapp commented 5 years ago

@muzzikapp thanks for this. Was there any reason why you weren't able to create PR?

@codekidX you are welcome. I didn't create a PR just because my fix is just intended to be used in my app. But if you think it is a good way of handling this error, i can create a PR as well.