Android Question List not initializing

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

DrownedBat

Member
Licensed User
Longtime User
Quite correct Erel, as usual. I am running into a "List not initialized" error when I try to populate that list with files that are in a specific folder, as per:

B4X:
Dim FilesFound As List
FilesFound.Initialize
FilesFound=File.ListFiles(File.DirRootExternal & "/My Folder")

My manifest editor for permissions reads as follows:

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
SetApplicationAttribute(android:largeHeap, "true")
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
SetApplicationAttribute(android:hardwareAccelerated, "true")

It would seem I have the external read/write permissions in place but something is causing the list not to be understood as "initialized". If, for example, I were to add
B4X:
FilesFound.SortCaseInsensitive(True)
I would trigger the same error.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

DrownedBat

Member
Licensed User
Longtime User
That's it! Thank you so much Erel; I am so out of touch on Android that I had no knowledge at all of Runtime Permissions as a THING. The last version of B4A I used was v4.0 so I'm catching up. I've got some reading to do but until then, I'll drop the targetSdkVersion down to 22 (for the time being). Thanks again!
P.S. Mistake removed.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I've got some reading to do but until then, I'll drop the targetSdkVersion down to 22 (for the time being).

Just be aware that you cannot submit a new app or update to Play Store if the targetSdkVersion is lower than 28.

- Colin.
 
Upvote 0

DrownedBat

Member
Licensed User
Longtime User
Oh, I know Colin. I was just trying to get it working again before I had to head off to an appointment. I'll bring it up into the future soon but it's still a few years out.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Please note, just because you initialized your list, does not mean that File.ListFiles returns an initialized list. Actually, the list you initialized is being replaced by the list that is returned by File.ListFiles and that list may be uninitialized.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please note, just because you initialized your list, does not mean that File.ListFiles returns an initialized list. Actually, the list you initialized is being replaced by the list that is returned by File.ListFiles and that list may be uninitialized.
Very true. This is a programming bug:
B4X:
Dim FilesFound As List
FilesFound.Initialize
FilesFound=File.ListFiles(File.DirRootExternal & "/My Folder")
Correct code:
B4X:
Dim FilesFound As List = File.ListFiles(File.DirRootExternal & "/My Folder")
 
Upvote 0
Top