Error when loading a list from LoadCSV

splatt

Active Member
Licensed User
Longtime User
B4X:
Sub btnFiles_Click
    Dim su As StringUtils
    Dim Table As List
    Dim fName, pegName As String
    Dim fd As FileDialog
    Dim fSize As Int
 
    table.Initialize
    fd.FastScroll = True
    fd.FilePath =File.DirRootExternal&"/Android/data/encoded.b4a/files/encoded" 
    fd.FileFilter = ".cat" 
    If fd.Show("Select Catalog File", "Yes", "No", "", Null) =DialogResponse.POSITIVE Then 
        Table = su.LoadCSV(fd.FilePath, fd.ChosenName, ",")
        Log(fd.FilePath&" , "&fd.ChosenName)
        For i = 0 To table.Size - 1
           pegName = table.Get(i)
           Log(pegName)
       Next
    End If
End Sub

I'm trying to read a file that contains imagefile names:
"1.gif","2.gif","3.gif","4.gif","5.gif","6.gif","7.gif","8.gif"

I get an error at this line: Table = su.LoadCSV(fd.FilePath, fd.ChosenName, ",")

java.lang.StringIndexOutOfBoundsException

What am I doing wrong?
 

splatt

Active Member
Licensed User
Longtime User
Saved the text file as UTF-8.

Now the file is loaded without errors.

B4X:
For i = 0 To table.Size - 1
   pegName = table.Get(i)
   Log(table.Size&" - "&pegName)
Next

When I execute this code, all I get is:
1 - [Ljava.lang.String;@481fd7d8
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User

Thanks Erel, that has worked. Bizarely, the first item is still wrapped in double quotes, the rest have been stripped off.
 
Upvote 0

Crolt

Member
Licensed User
Longtime User
coma separated CSV file

Sorry,
I'm quite new on B4A.
I'm still having the same problem even if I save it in Unicode.
If I change the the SeparatorChar from "," to ";" it works.
But I do not want to use it because I need to include more than one eMail address separated by semicolon.
Thank you,
Carlo

Saved the text file as UTF-8.

Now the file is loaded without errors.
 
Upvote 0

Crolt

Member
Licensed User
Longtime User
Ok,
now it works even with comma!
After the Unicode saving the text file was corrupted
(some hidden characters at the beginning, probably due to mishandling or some editors I tried!).


 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…