B4J Question StringUtils.SaveCSV

duneplodder

Active Member
Licensed User
Longtime User
I'm sure it's staring me in the face, but could someone tell me why this doesn't work:

B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
   #CommandLineArgs:
   #MergeLibraries: True
#End Region

Sub Process_Globals
  
End Sub

Sub AppStart (Args() As String)
Dim RecData As List, su As StringUtils

RecData.Initialize
RecData.Add("Fred")
RecData.Add("Bill")
RecData.AddAll(Array As String("Fred","Bill","Joe"))
Log(File.dirapp)
su.SaveCSV(File.DirApp, "MyData.csv",",",RecData)

End Sub

It throws up a "String cannot be cast to" error when run.
Also could someone remind me how to display code within a forum message please!
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
What line throws the Exception?

Code should be surrounded by [ CODE ] .... [/ CODE ] (without the spaces).
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Check out the documentation for StringUtils: https://www.b4x.com/android/help/stringutils.html#stringutils_savecsv This info will also be in the comments of your autocomplete menu for StringUtils.

The List that you pass to su.SaveCSV isn't supposed to be a List of Strings. It's supposed to be a List of Arrays of Strings. Each Array of Strings will represent a row in the resulting CSV file. The Exception is complaining that it cannot cast String to String[], I bet (in the future, it's more helpful to show the full error message and stack trace).
 
Upvote 0
Top