Android Question Sorting a Contact list gives java.lang.CLassCastException

Gerrard

Member
Licensed User
Longtime User
I have a program that lists the contacts in my phone in a listview. It works fine. Now I want to sort the listview. I have read similar posts and tried the suggestions but still get the ClassCastException error.
This is the Sub that gives the error, in that last For loop at the line
Contact = ListOfContacts.Get(i)

Sub Getcontacts
Dim Contacts2 As Contacts2
Dim line As String
Dim ListSize As Int
Dim mylist As List
mylist.Initialize
ListOfContacts.Initialize
ListOfContacts = Contacts2.GetAll(True, False)

ListSize = ListOfContacts.Size - 1
Log("Before mylist.add, ListSize=" & ListSize)
For i = 0 To ListSize 'TESTING
line = ListOfContacts.Get(i)
mylist.add(line)
Log("line " & i & line)
Next

mylist.Sort(True)

For i = 0 To ListSize 'TESTING
Log("Sort " & i & mylist.Get(i))
Next

ListOfContacts.Initialize
For i = 0 To ListSize
line = mylist.Get(i)
ListOfContacts.Add(line)
Log("Line "& i & line)
Next

For i = 0 To ListSize
Dim Contact As Contact
Contact = ListOfContacts.Get(i)
Log("i=" & i & " " & Contact) 'TESTING
If (Contact.PhoneNumber <>"" AND Contact.DisplayName <> "") Then
lvphone.SingleLineLayout.Label.TextSize = 15
lvphone.SingleLineLayout.ItemHeight = 40
lvphone.AddSingleLine(Contact.DisplayName &": " &Contact.PhoneNumber)
lvphone.ScrollingBackgroundColor =Colors.DarkGray
End If
Next
End Sub

What must I do to sort it out?
 
Top