android java.lang.IllegalArgumentException: Comparison method violates its general contract! 问题

android  java.lang.IllegalArgumentException: Comparison method violates its general contract! 问题

java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at java.util.TimSort.mergeLo(TimSort.java:743)
    at java.util.TimSort.mergeAt(TimSort.java:479)
    at java.util.TimSort.mergeCollapse(TimSort.java:406)
    at java.util.TimSort.sort(TimSort.java:210)
    at java.util.TimSort.sort(TimSort.java:169)
    at java.util.Arrays.sort(Arrays.java:2038)
    at java.util.Collections.sort(Collections.java:1891)

需求排序:数据列表中如果fileName的文件存在的话,放到列表的最上面

public class MyData{

        private String fileName;

        public void setfileName(String fileName){
        this.fileName=fileName;
        }

        public String getfileName(){
        return this.fileName;
        }

        }

    private void MySort(List<MyData> MyDatas){ 

        Collections.sort(MyDatas, new Comparator<MyData>() {
                    @Override
                    public int compare(MyData lhs, MyData rhs) { // lhs和rhs 都要用上,不然会出错,本人测试是这样的,具体不知为何
                        // TODO Auto-generated method stub
                        if (lhs == null || rhs == null)
                            return 0;
                        String path="/mnt/file/";
                        // file one
                        String name1= lhs.getfileName();
                        String filename1 = path + name1;
                        File file1 = new File(filename1);

                        // file two
                        String name2= rhs.getfileName();
                        String filename2 = path + name2;
                        File file2 = new File(filename2);

                        if (file1.exists() == true && file2.exists() == true) {
                            return 0;
                        } else {
                            if (file1.exists() == true) {
                                return 1;
                            } else {
                                return -1;
                            }
                        }
                    }
                });
                Collections.reverse(MyDatas);
    }
时间: 2024-11-05 19:48:43

android java.lang.IllegalArgumentException: Comparison method violates its general contract! 问题的相关文章

Java 异常解决之java.lang.IllegalArgumentException: Comparison method violates its general contract!

Java 异常解决 在你的代码前加一句 System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); 我也不知道什么原理,但是解决了!!!哈哈 Java 异常解决之java.lang.IllegalArgumentException: Comparison method violates its general contract!

java.lang.IllegalArgumentException: Comparison method violates its general contract!

背景 16号为了统一线上服务器运行环境,将两台服务器的Tomcat6+JDK6升级到Tomcat7+JDK7,本以为很简单的事情,升级后自己验证也没问题,没想到却悲剧了.升级后,过了半小时运营就找过来反馈问题,部分角色无法登陆系统,由于异常日志没有输出,没有找到问题,无奈回滚.今天我们就来说说JDK6升级到JDK7会遇到的坑.本文为了方便搜索,就直接以异常信息作为文章标题了. 复现 回滚后,到beta环境按照线上的权限配置,复现该问题,加上了error日志输出,输出了文章标题的异常,这个异常是在

Comparison method violates its general contract!

今天一个群里哥们儿碰到一个异常,抛到群里求解答,他的代码如下图: 抛出的异常信息为: Java代码   java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:868) at java.util.TimSort.mergeAt(TimSort.java:485) at java.util.TimSor

java-collections.sort异常Comparison method violates its general contract!

转载:http://www.tuicool.com/articles/MZreyuv 异常信息 java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:868) at java.util.TimSort.mergeAt(TimSort.java:485) at java.util.TimSort.me

[ Error 分析] Comparison method violates its general contract!

public static void main(String[] args) { List<Long> ret = new ArrayList<>(); int n = 103000; for(int i=0;i<n;i++){ ret.add(new Random().nextLong()); } Collections.sort( ret , new Comparator<Long>(){ @Override public int compare(Long o

Android java.lang.IllegalArgumentException: pointerIndex out of range

转载请注明:http://blog.csdn.net/aaawqqq Android   java.lang.IllegalArgumentException: pointerIndex out of range bug: 11-27 00:12:55.029: E/AndroidRuntime(22447): java.lang.IllegalArgumentException: pointerIndex out of range 11-27 00:12:55.029: E/AndroidRu

Android - java.lang.IllegalArgumentException: Receiver not registered

java.lang.IllegalArgumentException: Receiver not registered 从平台上可以看到Crash的错误问题, 出现了以下这条 java.lang.IllegalArgumentException: Receiver not registered 明明我OnResume有注册.OnPause有移除. 但为什么会发生这个问题 private BroadcastReceiver mReceiver = new BroadcastReceiver() {

Android java.lang.IllegalArgumentException: Object returned from onCreateLoader must not be a non-static inn

AsyncTaskLoader: http://developer.Android.com/intl/zh-CN/reference/android/content/AsyncTaskLoader.html 错误信息: java.lang.IllegalArgumentException: Object returned from onCreateLoader must not be a non-static inner member class: DownloadTask 原因: public

解决Android studio 启动报错java.lang.RuntimeException: java.lang.IllegalArgumentException

报错内容 Internal error. Please report to https://code.google.com/p/android/issues java.lang.RuntimeException: java.lang.IllegalArgumentException: Argument for @NotNull parameter 'name' of com/android/tools/idea/welcome/Platform.<init> must not be null