解析日期在Android 12中崩溃
我使用以下代码来解析日期来对列表进行排序:
Collections.sort(collaborationRoomModelList, new Comparator<CollaborationRoomModel>() {
DateFormat f = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
@Override
public int compare(CollaborationRoomModel lhs, CollaborationRoomModel rhs) {
try {
return f.parse(rhs.getDate()).compareTo(f.parse(lhs.getDate()));
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
});
此代码在Android 7上效果很好,但在Android 12中崩溃。下面是碰撞日志:
java.lang.IllegalArgumentException: java.text.ParseException: Unparseable date: "Tue Jun 07 14:40:24 GMT+10:00 2022"
at com.bizfluence.ui.business.collabmsglist.CollabMessageList$3$1.compare(CollabMessageList.java:389)
at com.bizfluence.ui.business.collabmsglist.CollabMessageList$3$1.compare(CollabMessageList.java:381)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1492)
at java.util.ArrayList.sort(ArrayList.java:1470)
at java.util.Collections.sort(Collections.java:206)
任何解决此问题的解决方案都非常感谢。
I am using the following code to parse date to sort a list:
Collections.sort(collaborationRoomModelList, new Comparator<CollaborationRoomModel>() {
DateFormat f = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
@Override
public int compare(CollaborationRoomModel lhs, CollaborationRoomModel rhs) {
try {
return f.parse(rhs.getDate()).compareTo(f.parse(lhs.getDate()));
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
});
This code works perfectly fine on Android 7 but crashes in android 12. Below is the crash log:
java.lang.IllegalArgumentException: java.text.ParseException: Unparseable date: "Tue Jun 07 14:40:24 GMT+10:00 2022"
at com.bizfluence.ui.business.collabmsglist.CollabMessageList$3$1.compare(CollabMessageList.java:389)
at com.bizfluence.ui.business.collabmsglist.CollabMessageList$3$1.compare(CollabMessageList.java:381)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1492)
at java.util.ArrayList.sort(ArrayList.java:1470)
at java.util.Collections.sort(Collections.java:206)
Any solution to fix this issue is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加当地解决了问题。在Android 7和12上都可以正常工作。
Adding the Local solved the issue. Works fine on both android 7 and 12.