B4J Question (SOLVED)Application crashes when TableView items are cleared

walterf25

Expert
Licensed User
Longtime User
Hello all, i haven't really played too much with B4J, i'am working on a very simple application which connects to a remote database on my hosting service, i'am using a tableview which shows the results of a search query, this all works perfect, but when i clear the items from the tableview the application crashes with the following error.


below is the relevant code, please let me know if there is anything i'm missing

B4X:
Sub searchresults_QueryComplete (Success As Boolean, Crsr As ResultSet)
    Dim sql2 As SQL = Sender
    If Success Then
    Log("success retrieving searchresults: " & Success)
    If tblsearchresults.Items.Size > 0 Then
        tblsearchresults.Items.Clear  'Here i clear the items from the previous search
    End If
    Do While Crsr.NextRow
    Dim row(7) As Object
    Log("first name: " & Crsr.GetString("First_Name") & " " & "Last Name :" &       Crsr.GetString("Last_Name") & " " & "Pet's Name: " & Crsr.GetString("Pet_Name"))
    row(0) = Crsr.GetString("First_Name")
    row(1) = Crsr.GetString("Last_Name")
    row(2) = Crsr.GetString("Pet_Name")
    row(3) = Crsr.GetString("Sex")
    row(4) = Crsr.GetString("Breed")
    row(5) = Crsr.GetString("Date")
    row(6) = Crsr.GetString("Clips_and_Comments")
    tblsearchresults.Items.Add(row)
    Loop
    Crsr.Close
    sql2.Close
    searchresults.Show
    Else
    Log("error occurred retrieving search results")   
    End If
End Sub

Thanks All,
Walter
 

walterf25

Expert
Licensed User
Longtime User

Sorry All, just figured it out, turns out i have to evaluate the index at the _SelectedRowChange event after clearing the items from the list.
B4X:
Sub tblsearchresults_SelectedRowChanged(Index As Int, Row() As Object)
If Index > -1 Then
    Dim date As Long
    txtname.Text = Row(0)
    txtlast.Text = Row(1)
    txtpetname.Text = Row(2)
    txtsex.Text = Row(3)
    txtbreed.Text = Row(4)
    date = DateTime.DateParse(Row(5))
    txtdate.Date = date
    txtcomments.Text = Row(6)
    'tblsearchresults.Items.Clear
    searchresults.Close
End If
End Sub

Thanks all.
Walter
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…