如何解决B4A中的“对象转换为字符串”错误

问题描述

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type DBResult (Tag As Object,**Columns As MaP**,Rows As List)
Type DBCommand (Name As String,Parameters() As Object)
Private const rdcLink As String = "http://192.168.8.100:17178/rdc"
End Sub

这是进程全局变量方法。这里 columns As Map 被初始化。 然而,下面代码中加粗的行给出了一个错误,“对象转换为字符串。这可能是一个编程错误。(警告 #7)”

Sub GetRecord
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("selectAllNames",Null)
Wait For (req.ExecuteQuery(cmd,Null)) JobDone(j As HttpJob)
If j.Success Then
    req.HandleJobAsync(j,"req")
    Wait For (req) req_Result(res As DBResult)
    'work with result
    'req.PrintTable(res)
    ***Log(res.Columns)***
    ListViewListTable.Clear
    For Each row() As Object In res.Rows
        Dim oBitMap As Bitmap
        Dim buffer() As Byte
        buffer = row(res.Columns.Get("gambar"))
        oBitMap = req.BytesToImage(buffer)
        ListViewListTable.AddTwoLinesAndBitmap(row(1),"See more...",oBitMap)
    Next
Else
    Log("ERROR: " & j.ErrorMessage)
End If
j.Release
End Sub

那么我应该怎么做才能消除错误

解决方法

如果列是地图? (它看起来是什么?)。

然后你可以使用这个来显示列:

For Each MyKey As String in res.Columns.Keys
   log("Key name = " & MyKey)
   log("Key value = " & res.Columns.Get(MyKey))
Next