解决这个异常很简单,只需要加上try catch即可
List<Map<String, Object>> list =new ArrayList<Map<String,Object>>();
try {
//针对counter 排序
//对容器进行降序排序的函数
Collections.sort(list,couSrot);
} catch (Exception e) {
}
下面的是比较大小的方法
@SuppressWarnings("unchecked")
static Comparator<Map<String, Object>> couSrot = new Comparator(){
public int compare(Object a0, Object a1) {
Map<String, Object> s1 = (Map<String, Object>) a0;
Map<String, Object> s2 = (Map<String, Object>) a1;
int count1= Integer.valueOf(s1.get("count")!=null?s1.get("count").toString():"0");
int count2= Integer.valueOf(s2.get("count")!=null?s2.get("count").toString():"0");
if(count1 != count2)
{
return count2 - count1;
}
return count2;
}
};
报错的原因可以参考这个博文自行脑补:http://www.tuicool.com/articles/MZreyuv