Bigkoo/Android-PickerView · error · IllegalArgumentException

startDate can't be later than endDate

Error message

startDate can't be later than endDate

What it means

TimePickerView.initWheelTime throws this IllegalArgumentException when a custom time range was configured via setRangDate/Builder with a startDate whose time is after the endDate. The wheels cannot be initialized with an inverted range, so construction fails immediately.

Solutions

  1. Swap the two Calendar arguments so the earlier one is passed as startDate
  2. Compare the Calendars and order them programmatically before building the picker
  3. Clamp start to at most end if the two come from independent inputs

Example fix

// before
pvTime.setRangDate(endDate, startDate); // swapped -> throws
// after
if (startDate.getTimeInMillis() > endDate.getTimeInMillis()) {
    Calendar tmp = startDate; startDate = endDate; endDate = tmp;
}
pvTime.setRangDate(startDate, endDate);
Defensive patterns

Strategy: validation

Validate before calling

if (start != null && end != null && start.getTimeInMillis() > end.getTimeInMillis()) {
    Calendar t = start; start = end; end = t; // reorder before setRangDate
}

Try / catch

try {
    TimePickerView pv = new TimePickerView.Builder(ctx).setRangDate(start, end).build();
} catch (IllegalArgumentException e) {
    // rebuild with default range or reordered dates
}

Prevention

When it happens

Trigger: Building a TimePickerView with .setRangDate(startDate, endDate) (or setStartDate/setEndDate) where startDate.getTimeInMillis() > endDate.getTimeInMillis(), e.g. swapped argument order.

Common situations: Swapping start/end parameters accidentally; computing both dates dynamically (e.g. 'now - 1y' and 'now') where rounding makes start end up after end; loading dates from config/user input without ordering them.

Related errors


AI-assisted analysis of Bigkoo/Android-PickerView@e200d8c063 (2026-09-07). Data as JSON: /api/errors/943595bb001c2a1f. Report an issue: GitHub.

Appendix: source

Thrown at pickerview/src/main/java/com/bigkoo/pickerview/view/TimePickerView.java:111

                        mPickerOptions.timeSelectChangeListener.onTimeSelectChanged(date);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        wheelTime.setLunarMode(mPickerOptions.isLunarCalendar);

        if (mPickerOptions.startYear != 0 && mPickerOptions.endYear != 0
                && mPickerOptions.startYear <= mPickerOptions.endYear) {
            setRange();
        }

        //若手动设置了时间范围限制
        if (mPickerOptions.startDate != null && mPickerOptions.endDate != null) {
            if (mPickerOptions.startDate.getTimeInMillis() > mPickerOptions.endDate.getTimeInMillis()) {
                throw new IllegalArgumentException("startDate can't be later than endDate");
            } else {
                setRangDate();
            }
        } else if (mPickerOptions.startDate != null) {
            if (mPickerOptions.startDate.get(Calendar.YEAR) < 1900) {
                throw new IllegalArgumentException("The startDate can not as early as 1900");
            } else {
                setRangDate();
            }
        } else if (mPickerOptions.endDate != null) {
            if (mPickerOptions.endDate.get(Calendar.YEAR) > 2100) {
                throw new IllegalArgumentException("The endDate should not be later than 2100");
            } else {
                setRangDate();
            }
        } else {//没有设置时间范围限制,则会使用默认范围。
            setRangDate();
        }

View on GitHub (pinned to e200d8c063)