Android Question How do you Initialize File.ListFiles(<path>)?

Sam H

Member
Licensed User
Longtime User
I am able to create a list of files, which works fine on my tablet but not on the emulator.

My code is:

Dim path1 = File.DirRootExternal
Dim fileList As List
fileList.Initialize()
fileList = File.ListFiles(path1)
fileList.sort()

The error shown is "java.lang.RuntimeException: Object should first be initialised (List)". The list was initialised in line 3, and it somehow get uninitialised in line 4. Any suggestions on why this is?

thanks
 

klaus

Expert
Licensed User
Longtime User
If you read the help text you would see that if there is no file, File.ListFiles returns an uninitialized List !
Returns a read only list with all the files and directories which are stored in the specified path.
An uninitialized list will be returned if the folder is not accessible.


You need to check If List.IsInitialized Then.
 
Upvote 0

Sam H

Member
Licensed User
Longtime User
Thanks, I realised this shortly after I had posted this as usual and forgot to say. It worked on my tablet as there were files, but as you say, on the emulator, there weren't any as I hadn't given it an emulated SD card, so it returned an empty list.

Thanks again
 
Upvote 0
Top