3

I'm sorting a List from java.util, with Gluon, on an Android Device. The application is not getting compiled for iOS (not enough ram) even with 8GB allocated, but that's another issue.

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

compile 'com.gluonhq:charm:4.3.2'

jfxmobile version = '3.2.4'

This line which causes 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 began searching and I found this post about NoSuchMethodError, so I tried to do the following, but alas it still crashes, and now I'm out of 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)

2 Answers 2

5

Both Comparator#comparing() and List#sort(Comparator) were added in API level 24 and your device is probably running a lower API level.

You'll probably have better luck with Collections#sort() that has been there since API level 1.

Sign up to request clarification or add additional context in comments.

1 Comment

Collections.sort(highscoreList, (highscore1, highscore2) -> highscore2.getScore() - highscore1.getScore()); solved the issue, thanks!
0

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

I called the function toSortedSet() of a LinkedHashSet. This function tries to call Comparator.naturalOrder() which needs API Level 24.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.