storage-chooser icon indicating copy to clipboard operation
storage-chooser copied to clipboard

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

Open yhs0602 opened this issue 6 years ago • 5 comments

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;
	}	//	
}

yhs0602 avatar Feb 24 '19 23:02 yhs0602

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.

codekidX avatar Feb 25 '19 17:02 codekidX

+1 My users are reporting this issue too

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

rahulpopuri avatar Jul 01 '19 15:07 rahulpopuri

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

muzzikapp avatar Nov 09 '19 12:11 muzzikapp

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

codekidX avatar Nov 10 '19 08:11 codekidX

@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.

muzzikapp avatar Nov 10 '19 20:11 muzzikapp