Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;) exception in sorting arraylist android

I'm trying to sort an ArrayList in Java in Android app but I'm getting this weird exception.

Code:

eventsList.sort(new Comparator<Event>() {         @Override         public int compare(Event event, Event t1) {             return event.getEventStartDate().compareTo(t1.getEventStartDate());         }     }); 

Exception:

java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;)V in class Ljava/util/List; or its super classes (declaration of 'java.util.List' appears in /system/framework/core-libart.jar) 
like image 875
Hossam Ghareeb Avatar asked Aug 15 '16 07:08

Hossam Ghareeb


1 Answers

ArrayList#sort() was added in API level 24 and runtimes below API level 24 don't have that method. Looks like your compileSdkVersion is at 24 so you got the code to compile in the first place.

Use Collections.sort(list, comparator) instead.

like image 134
laalto Avatar answered Sep 21 '22 15:09

laalto