I have an ArrayList and I am using the below code to sort it, the sortField here is of type string which works perfectly fine but sometimes it can also be a field of type Date and the below is throwing a class cast exception in such a case. What needs to be used such that it works in both the scenarios. Thanks a lot for the help in advance.
Collections.sort(tempList, new BeanComparator(sortField, String.CASE_INSENSITIVE_ORDER));
Below is the stack trace
2014-08-26 16:58:18,573 ERROR - - - java.lang.ClassCastException: java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
2014-08-26 16:58:18,573 INFO - - - Method execution failed:
java.lang.ClassCastException: java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
at org.apache.commons.beanutils.BeanComparator.compare(BeanComparator.java:155)
at java.util.TimSort.countRunAndMakeAscending(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at com.test.org.web.ajax.File.listFiles(FileUpload.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.directwebremoting.impl.CreatorModule$1.doFilter(CreatorModule.java:229)
at org.directwebremoting.impl.CreatorModule.executeMethod(CreatorModule.java:241)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:379)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:332)
at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:104)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:120)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)