Android Question List files

h4an

Member
Licensed User
Longtime User
I have an old program with this routine:
Private Sub ListaFiles(Dir As String)
Dim lstFiler As List
Dim strTemp As String

lstFiler = File.ListFiles(Dir)
For i = 0 To lstFiler.Size - 1
strTemp = lstFiler.Get(i)
If strTemp.IndexOf(".") = - 1 Or strTemp.IndexOf(".csv") > 0 Then
lsvFile.AddSingleLine(strTemp)
End If
Next

End Sub

When I try to use it in a B4X module I get an error on this row:

For i = 0 To lstFiler.Size - 1
error: java.lang.RuntimeException: Object should first be initialized (List).
I have try to put in lstFiler.Initialize before lstFiler = File.ListFiles(Dir) but it is the same error. How shall I do to get it work in a B4X module?
 

teddybear

Well-Known Member
Licensed User
I guess this error is from lsvFile instead of lstFiler
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I have an old program with this routine:
I think your problem may be in Dir. Since you are using an old app that might be using file.direxternal or something like that where it becomes an issue with newer OS in terms of permission. It also looks like you are using a listview. For newer projects it is recommended to use xCustomListview and B4XPages type of projects:
You code if you use code tags, will look better:
B4X:
Private Sub ListaFiles(Dir As String)
    Dim lstFiler As List
    lstFiler.Initialize
    Dim strTemp As String
    lstFiler = File.ListFiles(Dir)
    For i = 0 To lstFiler.Size - 1   'you can also use for each...
    strTemp = lstFiler.Get(i)
        If strTemp.IndexOf(".") = - 1 Or strTemp.IndexOf(".csv") > 0 Then
             lsvFile.AddSingleLine(strTemp)
            Log(strTemp)
        End If
    Next
End Sub
 
Upvote 0

h4an

Member
Licensed User
Longtime User
Thank you to put me in right direction, it is something with Dir. I have use DirDefaultExternal and it not work in the new application but in the old on same device?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have use DirDefaultExternal
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…