11

I was testing my app with the new Android 5.0 (API21) but was getting an error with the CalendarView

Caused by: java.lang.UnsupportedOperationException: CalendarView does not exists for the new DatePicker
   at android.widget.DatePickerCalendarDelegate.getCalendarView(DatePickerCalendarDelegate.java:501)
   at android.widget.DatePicker.getCalendarView(DatePicker.java:365)

For my surprise the error was not because there is no CalendarView in the NEW API21 DatePicker, in fact, there is no DatePicker in API21, just CalendarView.

The error was produced because I was hidding the Week Numbers in the CalendarView

picker.getCalendarView().setShowWeekNumber(false);

This instruction throws the UnsupportedOperationException, be warned no more Week Numbers in the CalendarView, they just disappeared it, no explanation.

1
  • I've had users report crashes with this same error, so now I'm going to take your advice and remove the line that hides the week numbers. Thank you for posting this! Feb 18, 2015 at 22:22

2 Answers 2

2

One problem that can cause this exception is that if your DatePicker mode is android:datePickerMode="calendar", DatePicker.getCalendarView would cause exception in post API 21, then in order to solve this, change the mode of your DatePicker to android:datePickerMode="spinner" and in java you can use from conditions to handle API greater than or equal to 21

1

I think you are getting confused. your requirement is "to hide week number" But actually there is no week Number in date picker neither in api21 nor below 21

so i suggest you skipping "picker.getCalendarView().setShowWeekNumber(false);" line and continue with rest of code.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.