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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With