I would like to compare my contacts to get an alphabetical order but I have this error :
java.lang.IllegalArgumentException: Comparison method violates its general contract!
This happen when I call :
Collections.sort(aVoid, new CustomComparator());
This is my CustomComparator :
public class CustomComparator implements Comparator<ContactItems> {
@Override
public int compare(ContactItems o1, ContactItems o2) {
if (o1.getName() == null || o2.getName() == null)
return 0;
else
return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
}
}
My aVoid
array is the result of the method @onPostExecute(List<ContactItems> aVoid)
of the class AsyncTaskGetContacts extends AsyncTask<Void, Void, List<ContactItems>>