Android Question KeyValueStore2 B4XTable1.SetData with strings

Rusty

Well-Known Member
Licensed User
Longtime User
I have a list of strings stored in a KVS. It was written with one program and I am trying to read it with another. The strings are all like "item1", "Item2"...
B4X:
    Commands.Contents = kvs.Get(1)
 
    Dim data As List
    data.Initialize
    For i = 0 To Commands.Contents.ItemName.Size -1
        Log(i & " - " & Commands.Contents.ItemName.Get(i))
        data.Add(Commands.Contents.ItemName.Get(i))  
        'note, Commands.Contents.ItemName is a list
        'I load the contents into another list only
        'because I got frustrated and tried this
        'I think it should work with the KVS list...
        'BTW, the LOGs show the correct content of the stored list...
    Next
    B4XTable1.AddColumn("Item", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.SetData(data)

When I hit the SetData line above it abends with:
Any insights will be appreciated, including a better way
Rusty
 
Last edited:

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Don,
Good question… B4XTable is library from Anywhere (B4a, B4J...etc. compatible). Found HERE
I don't have source code for this...
Rusty
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I don't have source code for this...
You are filling a List with sinple strings, right?
But if i remember correctly each item in the List should be an ARRAY of Objects (for each column one String). Not just ONE String.

B4X:
Dim Data As List
   Data.Initialize
   Dim rs As ResultSet = sql.ExecQuery("SELECT CustomerId, FirstName, LastName, Company, Address FROM customers")
   Do While rs.NextRow
       Dim row(4) As Object ' ATTENTION... Array
       row(0) = rs.GetDouble("CustomerId")
       row(1) = rs.GetString("FirstName") & " " & rs.GetString("LastName")
       row(2) = rs.GetString("Company")
       'Some of the values are Null. We need to convert them to empty strings:
       If row(2) = Null Then row(2) = ""
       row(3) = rs.GetString("Address")
       Data.Add(row) ' Adding an Array, not a String
   Loop
   rs.Close
   B4XTable1.SetData(Data)

Note that i saw the Lib but did not used it as of now.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…