Android DatePickerDialog can't correct an invalid selection?!

I'm having this issue I just now noticed. I pop open my Date Picker Dialog and hit (-) for the month twice to bring me down to February. This left the day at 29, and the year at 2014. This date doesn't exist. It lets me select it but when I hit Set an exception is thrown that I can not seem to catch.

The exception is pretty clear
System.ArgumentOutOfRangeException: Argument is out of range.

But how can I stop this from happening? I wrapped a Try..Catch in the OnCreateDialog where the return of a new DatePickerDialog is initialized. This is also where the debugger highlights indicating the source of this exception.

protected override Dialog OnCreateDialog(int id)
        //return base.OnCreateDialog(id);
        switch (id)
            case Core.DATE_START_DIALOG_ID:
                return new DatePickerDialog(this, OnDateStartSet,
                    State.Schedule.Filter.Start.Month - 1,
            case Core.DATE_END_DIALOG_ID:
                return new DatePickerDialog(this, OnDateEndSet,
                    State.Schedule.Filter.End.Month - 1,
    catch (Exception ex)
        Core.ShowAlert(this, "Invalid date selected", Shared.AlertButtons.OkOnly, null);
    return null;

Adding the Try...Catch did nothing, the hightlight still occurs on line
return new DatePickerDialog(this, OnDateStartSet,


  • DavidCarriganDavidCarrigan USMember

    OK so perhaps this isn't widely known. I continued looking into this and when I installed it on a new device, say Ice Cream Sandwich (api 14) or higher. This issue is fixed. I go to February and the days automatically switch to the 28th. If I switch down to Gingerbread (api 10) the issue is there. I'd still like to know how to catch and fix this as the app support ranges from 10 - 14 :(

Sign In or Register to comment.