How to fill ArrayList with paths to files assets?

Write the app "quiz flags of countries", a set of flags in the assets folder. There is a method that restarts the fragment when the settings changed. The mechanism, as I understand it, we snatch the way of the picture, and add it to the ArrayList, etc. the Thing is that for some reason gives an error at compile time, the method itself:
Code
public void resetQuiz() {
 AssetManager assets = getActivity().getAssets();
fileNameList.clear();

 // Use AssetManager to retrieve the image file names
 try {
 for(String region:regionSet){
 String[] paths = assets.list(region);
 for(String path:regionSet){
 fileNameList.add(path.replace(".png", ""));
}
}
}
 catch(IOException ex) {
 Log.e(TAG, "Error loading image file names", ex);
}



 correctAnswers = 0;
 totalGuesses = 0;

quizCountriesList.clear();

 int flagCounter = 1;
 int numberOfFlags = fileNameList.size();

 // Add FLAGS_IN_QUIZ random file quizCountriesList
 while (flagCounter <= FLAGS_IN_QUIZ) {
 int randomIndex = random.nextInt(numberOfFlags);

 // Get random file name
 String filename = fileNameList.get(randomIndex);

 //If the region is enabled but has not yet been selected
 if (!quizCountriesList.contains(filename)) {
quizCountriesList.add(filename);

}
flagCounter++;
}

 loadNextFlag(); //Start the quiz by loading the first flag
 }


Also post a link to Git
link

P. S. do Not expect, of course, that someone will go through my crutches, but still, there might be good people =)
P. S. S I do Not exclude that I do not understand, learn programming for Android book, there are many methods that are now deprecated, and trying to write, but this problem is already fighting 2-3 days =(
June 10th 19 at 16:55
2 answers
June 10th 19 at 16:57
Solution
At least error
for(String region:regionSet){
 String[] paths = assets.list(region);
 for(String path:regionSet){ <--------
 fileNameList.add(path.replace(".png", ""));
}
 }


What is the error you receive?
String[] paths = assets.list(region);
 for(String path:paths){

??? - Eulah.Hamill commented on June 10th 19 at 17:00
Issues that the negative border need to be positive. - Jack50 commented on June 10th 19 at 17:03
what kind of border it? The error text, and who it is, please. - Art_Christians commented on June 10th 19 at 17:06
in the logs I see this:
Description of the error

Caused by: java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Random.java:388)
at com.example.slave.flagquiz.MainActivityFragment.resetQuiz(MainActivityFragment.java:160)
at com.example.slave.flagquiz.MainActivity.onStart(MainActivity.java:66)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
at android.app.Activity.performStart(Activity.java:6992)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
- Jack50 commented on June 10th 19 at 17:09
bound must be positive, I understand that the "boundary must be positive" - Jack50 commented on June 10th 19 at 17:12
, nextInt wants the number is strictly greater than zero. Sheet nothing size zero. Why - most likely because of the indicated error. - Art_Christians commented on June 10th 19 at 17:15
Yes, that's the thing that I don't understand why there is nothing in the sheet that I add to the record. - Jack50 commented on June 10th 19 at 17:18
first , the specified bug fixed? Secondly, catch the exception and do nothing. In this case, it is possible that nothing will be added. In the logs it is? - Art_Christians commented on June 10th 19 at 17:21
fixed the error in the loop, it worked, a little typo in the code and not the file list took, for all the help - thank you! - Jack50 commented on June 10th 19 at 17:24
the answer mark solution - Art_Christians commented on June 10th 19 at 17:27
June 10th 19 at 16:59
kompilacja fine.
problems at the stage inflate R. layout.fragment_main (maybe just me)
and loadNextFlag();
in assets are the files (directories) without "-". naturally nextImage.indexOf('-') -1 gives
and it is poorly digested.
everything is written in logcat
Generally, it kompilacja, but the emulator crashes immediately, I read the logs, it says constantly that the negative border, as if you're talking about it, and say, as I understand it. But I don't understand why the indexOf gives minus one.
As I understand, we just each path is added to the list in the fragment give a random item in the list and every time this thing gets out, and I don't know why. - Eulah.Hamill commented on June 10th 19 at 17:02

Find more questions by tags Android