B4J Question SaveCSV2

MarcoRome

Expert
Licensed User
Longtime User
Hi All, i have this code:
B4X:
    Dim CSVHeaders As List
    CSVHeaders.Initialize2(Array As String("DESCRIZIONE","Qta Iniziale", "Residuo Magazzino","Qta Cantieri", "CANTIERE ROSSI","CANTIERE GIALLI","CANTIERE TEST"))
    Dim data As List
    data.Initialize2(Array As String("1","2","3","4","5","6","7"))
    Dim su As StringUtils
    su.SaveCSV2(File.DirApp, "export.csv",",", data,CSVHeaders)

and this error:

WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Error occurred on line: 23 (Main)
java.lang.ClassCastException: class java.lang.String cannot be cast to class [Ljava.lang.String; (java.lang.String and [Ljava.lang.String; are in module java.base of loader 'bootstrap')
at anywheresoftware.b4a.objects.StringUtils.SaveCSV2(StringUtils.java:74)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
at b4j.example.main.start(main.java:38)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)

Where i wrong ?
 

klaus

Expert
Licensed User
Longtime User
SaveCSV2 needs a List of Arrays for the table?
One array per row.
B4X:
    Dim CSVHeaders As List
    CSVHeaders.Initialize2(Array As String("DESCRIZIONE","Qta Iniziale", "Residuo Magazzino","Qta Cantieri", "CANTIERE ROSSI","CANTIERE GIALLI","CANTIERE TEST"))
    Dim data As List
    Dim row() As String  = Array As String("1","2","3","4","5","6","7")
    data.Initialize
    data.Add = row
    Dim su As StringUtils
    su.SaveCSV2(File.DirApp, "export.csv",",", data,CSVHeaders)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Thank you for your reply Klaus.I did a previous test with row (0) .. etc but I still had the error. I will try
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
B4X:
    Dim CSVHeaders As List
    CSVHeaders.Initialize2(Array As String("DESCRIZIONE","Qta Iniziale", "Residuo Magazzino","Qta Cantieri", "CANTIERE ROSSI","CANTIERE GIALLI","CANTIERE TEST"))
    Dim data As List
    Dim row() As Object  = Array ("1","2","3","4","5","6","7")
    data.Initialize
    data.Add(row)
    Dim su As StringUtils
    su.SaveCSV2(File.DirApp, "export.csv",",", data,CSVHeaders)

Error was

B4X:
Dim row() As Object  = Array ("1","2","3","4","5","6","7")
data.Add = row
correct
B4X:
Dim row() As String  = Array As String("1","2","3","4","5","6","7")
data.Add(row)
 
Last edited:
Upvote 0
Top