###前提・実現したいこと
Personクラスを名前、年齢の2つのキーでソートをしたいです。
しかし、様々な方法を試しましたがすべてエラーになります。
どうにかしてソートする方法はありませんでしょうか。
また、Javaでも.NETのLINQのように書ければなぁ。。。と思っています。
いいライブラリ等ご存知でしたら教えてください><
###該当のソースコード
- MainActivity.java
Java
1// Person クラス 2class Person { 3 public Person(String name, Integer age){ 4 this.name = name; 5 this.age = age; 6 } 7 8 private String name; 9 public String getName() { 10 return name; 11 } 12 13 private Integer age; 14 public Integer getAge() { 15 return age; 16 } 17} 18 19@Override 20protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_main); 23 24 // persons にダミーデータを入れる 25 List<Person> persons = new ArrayList<>(); 26 persons.add(new Person("a", 3)); 27 persons.add(new Person("b", 2)); 28 persons.add(new Person("b", 4)); 29 persons.add(new Person("c", 1)); 30 31 // persons をソートする 32 persons.sort(comparing(Person::getName, reverseOrder()).thenComparing(Person::getAge)); 33 34 // 結果を出力する 35 for(Person p : persons) { 36 System.out.println(p.name + p.age); 37 } 38}
###発生している問題・エラーメッセージ
03-14 10:16:07.788 13100-13100/com.example.user01.myproject W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41c33638) 03-14 10:16:07.798 13100-13100/com.example.user01.myproject E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.user01.myproject, PID: 13100 java.lang.NoClassDefFoundError: com/example/user01/myproject/-$Lambda$0 com.example.user01.myproject.MainActivity.onCreate(MainActivity.java:42) android.app.Activity.performCreate(Activity.java:5246) android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169) android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271) android.app.ActivityThread.access$800(ActivityThread.java:144) android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) android.os.Handler.dispatchMessage(Handler.java:102) android.os.Looper.loop(Looper.java:136) android.app.ActivityThread.main(ActivityThread.java:5179) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:515) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:614) de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.user01.myproject.-$Lambda$0" on path: DexPathList[[zip file "/data/app/com.example.user01.myproject-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.user01.myproject-2, /vendor/lib, /system/lib]] dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) java.lang.ClassLoader.loadClass(ClassLoader.java:497) java.lang.ClassLoader.loadClass(ClassLoader.java:457) com.example.user01.myproject.MainActivity.onCreate(MainActivity.java:42) android.app.Activity.performCreate(Activity.java:5246) android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169) android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271) android.app.ActivityThread.access$800(ActivityThread.java:144) android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) android.os.Handler.dispatchMessage(Handler.java:102) android.os.Looper.loop(Looper.java:136) android.app.ActivityThread.main(ActivityThread.java:5179) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:515) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:614) de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) dalvik.system.NativeStart.main(Native Method)
###試したこと
- Lightweight-Stream-APIの利用
Android 7.0が最低条件となるので使えなかった。
Android 4.4以上の端末で動くアプリを作りたい。
- IxJavaの利用
問題なく動作した。
しかし、orderByは存在するが、thenByが存在しない為
複数キーでのソートができなかった。
- jLinqerの利用
以下のエラーが出てコンパイルができなかった。
Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Predicate Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Predicate Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Function Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.Comparator Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.Comparator Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.Comparator Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.Comparator Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Predicate Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.lang.Iterable
###補足情報(言語/FW/ツール等のバージョンなど)
- Android Studio 2.3
- Java 8を使用(こちらを参考にしました。)
https://developer.android.com/guide/platform/j8-jack.html?hl=ja
- JDK 1.8.0_121
- JRE 1.8.0_121
- アプリ動作テスト端末 Android 4.4(KitKat)
###2017/03/14 AM 11:52追記
情報追加
コードを一切変更せずに 以下の端末でテストしましたので結果を追加します。
Android API Level | Android Version | 結果 |
---|---|---|
23 | 6.0 | NG |
24 | 7.0 | OK |
25 | 7.1 | OK |
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/14 06:59 編集
2017/03/14 05:02
2017/03/14 05:26 編集
2017/03/14 05:41
2017/03/14 06:51 編集