我现在想 按照 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);的时候报错 空指针异常
我写的部分代码是这样的: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);的时候报错 空指针异常
帮下
System.out.println(listnew.size()+((KdMenu)listnew.get(0)).getMname());
Collections.sort(listnew, comp);
我这样打印有值出来
// 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;
}
}