string utils loadcsv index out of bounds error

Eduard

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Resume
   Dim x As StringUtils
   Dim serverantwoord As List
   Dim bestand As List
   bestand.Initialize
   bestand.Add("#00,543,5,5,-1")
   bestand.Add("#10,345=,435")
   File.WriteList(File.DirInternalCache,"bestand.csv",bestand)
   Dim serverantwoord As List
   Msgbox(File.ReadString(File.DirInternalCache,"bestand.csv"),"")
   Dim su As StringUtils
   serverantwoord=su.LoadCSV(File.DirInternalCache,"bestand.csv",",")
   Msgbox(serverantwoord.Size,"size")

** Activity (main) Resume **
main_activity_resume (java line: 263)


java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(String.java:1651)
at anywheresoftware.b4a.objects.StringUtils.ReadWord(StringUtils.java:258)
at anywheresoftware.b4a.objects.StringUtils.LoadCSV2(StringUtils.java:222)
at anywheresoftware.b4a.objects.StringUtils.LoadCSV(StringUtils.java:135)
at b4a.example.main._activity_resume(main.java:263)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at b4a.example.main.afterFirstLayout(main.java:91)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)


at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
at dalvik.system.NativeStart.main(Native Method)
java.lang.StringIndexOutOfBoundsException

It seems that Loadcsv can't read a file of more than one line (one line works, two or more doesn't work)

Any an idea whats wrong?
 

Eduard

Active Member
Licensed User
Longtime User
I think it must be a bug.

I have a work around. I use File.ReadList(dir,filename) to load the csv-lines and then split every line with

Dim fld() As String
fld=Regex.Split(",",line)
 
Upvote 0
Top