B4J Question LoadCSV error with jStringUtils

giannimaione

Well-Known Member
Licensed User
Longtime User
a file csv contain data:

B4X:
item1;alfa1;beta1
item2;alfa2;beta2
item3;alfa3;beta3
empty row
empty row

now, my code is:

B4X:
Dim su As StringUtils
Dim ItemList As List
ItemList = su.LoadCSV (myPath, NameCSV, ";")

log error is:
B4X:
importcounter._leggicounter (java line: 137)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1680
    at java.lang.String.substring(String.java:1967)
    at anywheresoftware.b4a.objects.StringUtils.ReadWord(StringUtils.java:243)
    at anywheresoftware.b4a.objects.StringUtils.LoadCSV2(StringUtils.java:207)
    at anywheresoftware.b4a.objects.StringUtils.LoadCSV(StringUtils.java:120)
    at j.Statistiche.importcounter._leggicounter(importcounter.java:137)
    at j.Statistiche.main._btcounter_action(main.java:100)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)

trouble is empty row at end of file CSV
Is there a solution?
 

giannimaione

Well-Known Member
Licensed User
Longtime User
changed
B4X:
Dim ItemList As List
ItemList = File.ReadList (myPath, NameCSV)
Dim OB() As Object
For x = 0 to ItemList.Size-1
   OB=Regex.Split(";", ItemList.Get(x))
   'here i have OB(0), OB(1), and OB(2) and i can test if it's empty
Next
 
Upvote 0

giannimaione

Well-Known Member
Licensed User
Longtime User
because, I receive an archive from some_several store counter (see image), via email.
 

Attachments

  • antitaccheggio.jpg
    antitaccheggio.jpg
    79.8 KB · Views: 227
Upvote 0

RWK

Member
Licensed User
I have same problem with amazon Transfer Files...
Don't know why the hell they are including 7 lines of bullshit text at the beginning of their export files...
after that the data begins..
It would be fine if LoadCSV could be extended like Excel Import:

B4X:
Workbooks.OpenText Filename:=pfad, Origin:=65001, _
        StartRow:=7, DataType:=xlDelimited,
        Comma:=True, local:=True

Anyway....time to switch to get the data per Amazon Financal Data API
 
Upvote 0
Top