你能看到我在这段代码中做错了吗?我正在使用DBUtils来填充一些文本框,但是在“Get”行上我得到了一个“Null指针异常”。我还使用Toast来确保intCurrentId确实有一个值。
这是我使用的代码:
Sub ListViewPeopleEventHandler_ItemClick (Position As Int, Value As Object)
' Update the details area.
'-------------------------
Dim valuesFromTheListView() As String
valuesFromTheListView = Value
intCurrentId = valuesFromTheListView(0)
Dim mapOfTableFields As Map
mapOfTableFields = DBUtils.ExecuteMap(SQL, _
"SELECT Id, FirstName, LastName FROM PeopleToVisit WHERE id = ?", _
Array As String(intCurrentId))
ToastMessageShow(intCurrentId, False)
' I get the error on this next line.
'-------------------------------------
EditTextFirstName.Text = mapOfTableFields.Get("FirstName")
EditTextFirstName.RequestFocus
EditTextFirstName.SelectAll
EditTextFirstName.Color = Colors.Cyan
EditTextLastName.Text = mapOfTableFields.Get("LastName")
EditTextLastName.RequestFocus
EditTextLastName.Color = Colors.Cyan
tableMode = "Edit"
Activity.Title = "Maintenance - Result Of Visit *** EDIT ***"
End Sub
这是数据库表的结构:
SQL.ExecNonQuery("CREATE TABLE PeopleToVisit (" & _
"Id INTEGER PRIMARY KEY, " & _
"FirstName TEXT, " & _
"LastName TEXT, " & _
"Address1 TEXT, " & _
"Address2 TEXT, " & _
"City TEXT, " & _
"State TEXT, " & _
"Zip TEXT, " & _
"PrimaryPhone TEXT, " & _
"SecondaryPhone TEXT, " & _
"Email TEXT, " & _
"LastVisitNote TEXT " & _
")")
感谢。
答案 0 :(得分:0)
我不确定为什么DBUtils版本不起作用但是当我在子程序的修订版本中使用游标时,一切正常。
Sub ListViewPeopleEventHandler_ItemClick (Position As Int, Value As Object)
' Update the details area.
'-------------------------
Dim valuesFromTheListView() As String
Dim oRecordSet As Cursor
valuesFromTheListView = Value
intCurrentId = valuesFromTheListView(0)
oRecordSet = SQL.ExecQuery( _
"SELECT Id, FirstName, LastName " & _
"FROM PeopleToVisit " & _
"WHERE id = " & intCurrentId)
If oRecordSet.RowCount > 0 Then
oRecordSet.Position = 0
EditTextFirstName.Text = oRecordSet.GetString("FirstName")
EditTextLastName.Text = oRecordSet.GetString("LastName")
End If
EditTextFirstName.RequestFocus
EditTextFirstName.SelectAll
EditTextFirstName.Color = Colors.Cyan
EditTextLastName.RequestFocus
EditTextLastName.Color = Colors.Cyan
tableMode = "Edit"
Activity.Title = "Maintenance - Result Of Visit *** EDIT ***"
End Sub