我现在想 按照 KdMenu 这个类的 method属性 对这个list进行排序
我写的部分代码是这样的:Comparator comp = new CollatorComparator();
Collections.sort(listnew, comp);
public static class CollatorComparator implements Comparator {
        Collator collator = Collator.getInstance();         public int compare(Object element1, Object element2) {
         ;
            CollationKey key1 = collator.getCollationKey(((KdMenu)element1).getMethod());
            CollationKey key2 = collator.getCollationKey(((KdMenu)element2).getMethod());
            return key1.compareTo(key2);
        }
  }现在执行到
 Collections.sort(listnew, comp);的时候报错  空指针异常

解决方案 »

  1.   

    csdn 里面的高手呢,,,
    帮下
      

  2.   

    listnew这个在哪创建的呢??所有代码
      

  3.   

    Comparator comp = new CollatorComparator();
    System.out.println(listnew.size()+((KdMenu)listnew.get(0)).getMname());
         Collections.sort(listnew, comp); 
    我这样打印有值出来
      

  4.   

    KdMenu   部分代码public class KdMenu  implements java.io.Serializable {
        // Fields         private Integer mid;
         private String mname;     private String method;  public Integer getMid() {
            return this.mid;
        }
        
        public void setMid(Integer mid) {
            this.mid = mid;
        }    public String getMname() {
            return this.mname;
        }
        
        public void setMname(String mname) {
            this.mname = mname;
        }
     public String getMethod() {
            return this.method;
        }
        
        public void setMethod(String method) {
            this.method = method;
        }
    }