Android Question SaveCsv Error

sonistp

Member
I got error java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.String[] when trying savecsv. Anyone can help me ? Please.
B4X:
Sub savedata
    Dim su As StringUtils
    Dim sb As StringBuilder
    Dim rows As List
    rows.Initialize
    sb.Initialize
    Dim ob,co,dw As Int
    Dim Arr(3) As String
    co=txtmpco.Text.Replace(",","")
    ob=txtmpob.Text.Replace(",","")
    dw=txtmpco.Text.Replace(",","")
    Arr(0)=ob
    Arr(1)=co
    Arr(2)=dw
    rows.AddAll(Arr)
    Log(rows)
    su.SaveCSV(File.DirDefaultExternal,"MP0320.CSV",",",rows)

End Sub
 

sonistp

Member
Never use File.DirDefaultExternal. Search for "runtime permissions" for more information.

This is the mistake: rows.AddAll(Arr)
AddAll expands the array and adds multiple items. You need to use Add:
B4X:
rows.Add(arr)
'or nicer:
rows.Add(Array As String(ob, co, dw))
(ArrayList) [[Ljava.lang.String;@52812418] I got this in my log after used
B4X:
rows.Add(Array As String(ob, co, dw))
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Another option:
Are you trying to say something like this or am I bucking your train of thought and messing with your solution?
B4X:
Dim i As Int
    For Each row() As String In rows
        Dim list As List = row
        For j=0 To list.Size-1
            Log(list.Get(j))    'display the individual items        
        Next
        i=i+1
    Next
 
Upvote 0
Top