Anyway, in this case, there was a typo in my example -- should have been imgURLs rather than imgUrls
Ron McLeod wrote:Does this stack entry: com.benvanj.android.outstagram.Share.GalleryFragment.setupGridView(GalleryFragment.java:165)
correspond to this line of code: setImage(imgURLs.get(0), galleryImage, mAppend); ??
Ron McLeod wrote:
If you are trying to view images for a directory which contains zero files, the imgURLs list will be empty. Trying to reference element 0 (the first element in the list) will result in an IndexOutOfBoundsException since the list doesn't contain any elements.
Stephan van Hulst wrote:Welcome to CodeRanch!
The obvious question is, are you sure that the directories you are listing have files in them?
Can you show us the stack trace? I don't think the error has anything to do with the line you indicated.
There are many issues with your code you can fix though.
Don't create a class for the sole purpose of holding constants. Keep constants in the class that uses them. Make them static and final. Don't use String or File to represent file paths. Use Path. This advice may be different for Android though. Don't use more specific types than you need. Use List or Set for the return types of your methods, not ArrayList. Don't name variables of a collection type "array". They're not arrays. Prefer enhanced for-loops over indexed loops, or use the stream API. Don't access a collection twice for the same element. Store the element in a local variable. Don't perform unnecessary null-checks. You don't need to keep track of a list of directories if you use Path, because you can just look up the parent directory.
Your problem is most likely caused by not using the Android API correctly though. You should probably be using Context, ContentResolver and MediaStore to look for images.