B4J Question String cannot be cast to [Ljava.lang.Object;

gezueb

Active Member
Licensed User
Longtime User
Hi All
The code below casts an exception at the statement marked
B4X:
    Dim AL As List
    AL.Initialize
    AL.AddAll (Array As String("a", "b", "c","d","e","f","g","h","i","j","k","l","m"))
    AL.AddAll (Array As String("q", "r", "s","t","u","v","w","x","y","z","1","2","3"))
    For i = 0 To AL.Size-1
        Dim Row() As Object
        Row = AL.Get(i) 'throws exception
        TableViewAssetList.Items.Add(Row)
    Next
I cannot figure out why. Thanks for help.
 

gezueb

Active Member
Licensed User
Longtime User
I found a solution that works:
B4X:
    Dim AL As List
    AL.Initialize
    Dim Row() As Object = Array ("a", "b", "c","d","e","f","g","h","i","j","k","l","m")
    AL.Add(Row)
    Dim Row() As Object = Array ("q", "r", "s","t","u","v","w","x","y","z","1","2","3")
    AL.Add(Row)
    Dim Row() As Object = Array ("A", "B", "C","D","E","F","G","H","I","J","K","L","M")
    AL.Add(Row)
    For i = 0 To AL.Size-1
        TableViewAssetList.Items.Add(AL.Get(i))
    Next
Thank you anyway, Agraham
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Or maybe
B4X:
    TableViewAssetList.Items.AddAll(Array As String("a", "b", "c","d","e","f","g","h","i","j","k","l","m"))
    TableViewAssetList.Items.AddAll(Array As String("q", "r", "s","t","u","v","w","x","y","z","1","2","3"))
    TableViewAssetList.Items.AddAll(Array As String("A", "B", "C","D","E","F","G","H","I","J","K","L","M"))

Unless you need to build the list (this looks like test data in your post), if so you can just point the tableview at it after you build the list.
B4X:
TableViewAssetList.Items = AL
the plus side is any changes you make to the list will be reflected in the Tableview - downside if you clear the list the Tableview will be empty.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Daestrum, thats an excellent idea, I will update my code with that:
B4X:
TableViewAssetList.Items = AL
By the way, yes, the data is just for tests. The final data will have to be individually calculated items, but as long as the result is strings, this will work okay. Thanks to all of you.
 
Upvote 0
Top