UnsupportedOperationException: CalendarView r
I have a problem with date picking in my project. I am getting the error:
java.lang.UnsupportedOperationException: CalendarView does not exists for the new DatePicker
at android.widget.DatePickerCalendarDelegate.getCalendarView(DatePickerCalendarDelegate.java:498)
at android.widget.DatePicker.getCalendarView(DatePicker.java:377)
at jadezabiore.spot.pl.jadezabiorepl.dialogs.DialogWithCalendar$1.onClick(DialogWithCalendar.java:56)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
only for the lipopic system. Is there a way to handle this?
Edit: This is problematic code:
IDatePickerInFilter act = (IDatePickerInFilter) activity;
datePicker.setCalendarViewShown(false);
act.getDateDialog(new DateToTimestampConverter().getStringDateFromTimestamp(datePicker.getCalendarView().getDate()));
source to share
The real problem is how to get the selected date from API 21. The pre-21 common approach was to use CalendarView
API 21+, the only possible way seems to provide OnDateChangedListener
in DataPicker
init
.
datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view,
int year, int monthOfYear, int dayOfMonth) {
// do the date stuff
}
});
The error message is also a bit over the top - "new DatePicker" does not refer to the new DatePicker (so you can expect to be able to run it), but to the new version of DatePicker available since API 21 (which throws an error whenever you ask CalendarView
).
source to share