B4J Question LoadCSV error with jStringUtils

Discussion in 'B4J Questions' started by giannimaione, Jun 14, 2019.

  1. giannimaione

    giannimaione Well-Known Member Licensed User

    a file csv contain data:

    Code:
    item1;alfa1;beta1
    item2;alfa2;beta2
    item3;alfa3;beta3
    empty row
    empty row
    now, my code is:

    Code:
    Dim su As StringUtils
    Dim ItemList As List
    ItemList = su.LoadCSV (myPath, NameCSV, 
    ";")
    log error is:
    Code:
    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?
     
  2. klaus

    klaus Expert Licensed User

    Yes, remove the empty rows :).
     
  3. giannimaione

    giannimaione Well-Known Member Licensed User

    changed
    Code:
    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
     
  4. klaus

    klaus Expert Licensed User

    For me, the first question is:
    Why do you have empty rows in the file?
     
    Last edited: Jun 14, 2019
  5. giannimaione

    giannimaione Well-Known Member Licensed User

    because, I receive an archive from some_several store counter (see image), via email.
     

    Attached Files:

  6. klaus

    klaus Expert Licensed User

    Well, I understand.
    That means that their system is not working well, and of course, you cannot improuve it.
    Therefore, unfortunately, you need to check everything on your own.
     
  7. RWK

    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:

    Code:
    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
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim s As String = File.ReadString(...)
    s = s.Trim
    File.WriteString(..., s)
    'load the new file
     
  9. raphaelcno

    raphaelcno Active Member Licensed User

    You may add
    Code:
    If ItemList.Size > 0 Then
    before
    Code:
    For x = 0 to ItemList.Size-1
    to avoid a crash :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice