JasonJun128
2015-06-24 12:24
采纳率: 100%
浏览 2.0k
已采纳

jsp中无法使用Collection.sort

各位大神,我在Message类里实现了Comparable接口,
public int compareTo(Message m)
{
if(this.Time.before(m.getTime()))
{
return 1;
}
else
return -1;
}

但在jsp页面里Collections.sort()对list排序时会报错
错误信息如下:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.ClassCastException: Information.Message cannot be cast to java.lang.Comparable
java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:290)
java.util.ComparableTimSort.sort(ComparableTimSort.java:157)
java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
java.util.Arrays.sort(Arrays.java:472)
java.util.Collections.sort(Collections.java:155)
org.apache.jsp.weixin1.wx_jsp._jspService(wx_jsp.java:208)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • fanst_ 2015-06-24 14:35
    已采纳

    java.lang.ClassCastException: Information.Message cannot be cast to java.lang.Comparable
    Message没有写implements Comparable?

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题