NoSuchMethodError - static method comparison (java / util / Comparator)

I am sorting List

from java.util

using Gluon on an android device. The app is not going to be compiled for iOS (not enough bar) even with 8GB allocated, but that's another problem.

classpath 'org.javafxports:jfxmobile-plugin:1.3.4'

compile 'com.gluonhq:charm:4.3.2'

jfxmobile version = '3.2.4'

This is the line that is causing the crash:

highscoreList.sort(comparing(Highscore::getScore).reversed()); //#89

03-22 09:42:14.709 27312 27337 E AndroidRuntime: FATAL EXCEPTION: JavaFX Application Thread
03-22 09:42:14.709 27312 27337 E AndroidRuntime: Process: com.x.pacman, PID: 27312
03-22 09:42:14.709 27312 27337 E AndroidRuntime: java.lang.NoSuchMethodError: No static method comparing(Ljava/util/function/Function;)Ljava/util/Comparator; in class Ljava/util/Comparator; or its super classes (declaration of 'java.util.Comparator' appears in /system/framework/core-libart.jar)
03-22 09:42:14.709 27312 27337 E AndroidRuntime:        at com.x.pacman.HighscoreUtil.readHighscoreList(HighscoreUtil.java:89)

      

I started searching and I found this post about NoSuchMethodError so I tried to do the following but alas it still crashes and now I have no ideas

Comparator<Highscore> comparator = new Comparator<Highscore>() {
    @Override
    public int compare(Highscore highscore1, Highscore highscore2) {
        return highscore1.getScore() - highscore2.getScore();
    }
};

highscoreList.sort(comparator); //#97


03-22 11:30:48.836 16547 16570 E AndroidRuntime: 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)
03-22 11:30:48.836 16547 16570 E AndroidRuntime:        at com.kaufland.pacman.HighscoreUtil.readHighscoreList(HighscoreUtil.java:97)

      

+3


source to share


2 answers


Both Comparator#comparing()

and List#sort(Comparator)

have been added to the API level 24 and your device is probably working a lower API levels.



You would probably be in luck with the Collections#sort()

one that has been there since API level 1.

+4


source


Just for your reference. I got this error while using http://www.vavr.io/ collections.

I called the toSortedSet () function of the LinkedHashSet . This function tries to call Comparator.naturalOrder () , which requires API level 24.



If you must use a lower level API, just use the toSortedSet (Comparator) overloaded function and pass in a suitable comparator.

0


source







All Articles