这段代码直到几天前才有效。现在它不再适用于 android 版本 6.0。它确实适用于 7.0 及更高版本。
public void setToDate(String quickDate) {
DateTime toDate = new DateTime();
if (quickDate.equals(context.getString(R.string.quickDate_today))) {
fromDate = fromDate.withTimeAtStartOfDay();
toDate = DateUtils.endOfDay(toDate);
}
....
}
/**
* @return a copy of dateTime with the time set to 11:59:59.999 pm.
*/
public static DateTime endOfDay(DateTime dateTime) {
return dateTime.withTime(23, 59, 59, 999);
}
这是奇怪的事情,如果我将 withTime() 调用移动到直接调用而不是像这样的实用方法中:
public void setToDate(String quickDate) {
DateTime toDate = new DateTime();
if (quickDate.equals(context.getString(R.string.quickDate_today))) {
fromDate = fromDate.withTimeAtStartOfDay();
toDate = toDate.withTime(23, 59, 59, 999);
}
....
}
然后代码工作,没有抛出异常。为什么?我怎样才能让它再次在实用程序方法中工作?
堆栈跟踪:
Process: com.salesrabbit.android.sales.universal, PID: 29358
java.lang.ExceptionInInitializerError
at com.salesrabbit.android.sales.universal.canvass.filter.filters.Filter.setQuickFromAndToDates(Filter.java:273)
at com.salesrabbit.android.widget.FilterView.lambda$loadQuickDateMenu$3$FilterView(FilterView.java:203)
at com.salesrabbit.android.widget.FilterView$$Lambda$3.onMenuItemClick(Unknown Source)
at android.support.v7.widget.PopupMenu$1.onMenuItemSelected(PopupMenu.java:108)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
at android.support.v7.view.menu.MenuPopup.onItemClick(MenuPopup.java:127)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3066)
at android.widget.AbsListView$3.run(AbsListView.java:3903)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Unknown pattern character 'X'
at java.text.SimpleDateFormat.validatePatternCharacter(SimpleDateFormat.java:323)
at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:312)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:365)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:258)
at com.salesrabbit.android.util.DateUtils.<clinit>(DateUtils.java:31)