material-components/material-components-android · error · IllegalStateException

Slider value(%s) must be greater or equal to valueFrom(%s),

Error message

Slider value(%s) must be greater or equal to valueFrom(%s), and lower or equal to valueTo(%s)

What it means

Thrown by validateValues() when any of the slider's current values (each thumb's position) falls outside [valueFrom, valueTo]. This commonly happens after shrinking the range while old values are still set, or after setValues() with values beyond the bounds. The message includes the offending value, valueFrom, and valueTo.

Source

Thrown at lib/java/com/google/android/material/slider/BaseSlider.java:749

    if (stepSize > 0.0f && !valueLandsOnTick(valueTo)) {
      throw new IllegalStateException(
          String.format(EXCEPTION_ILLEGAL_STEP_SIZE, stepSize, valueFrom, valueTo));
    }
  }

  private void validateValues() {
    if (valueFrom >= valueTo) {
      throw new IllegalStateException(
          String.format(EXCEPTION_ILLEGAL_VALUE_FROM, valueFrom, valueTo));
    }

    for (Float value : values) {
      if (value < valueFrom || value > valueTo) {
        throw new IllegalStateException(
            String.format(EXCEPTION_ILLEGAL_VALUE, value, valueFrom, valueTo));
      }
      if (stepSize > 0.0f && !valueLandsOnTick(value)) {
        throw new IllegalStateException(
            String.format(EXCEPTION_ILLEGAL_DISCRETE_VALUE, value, valueFrom, stepSize, stepSize));
      }
    }
  }

  private void validateMinSeparation() {
    final float minSeparation = getMinSeparation();
    if (minSeparation < 0) {
      throw new IllegalStateException(
          String.format(EXCEPTION_ILLEGAL_MIN_SEPARATION, minSeparation));
    }
    if (stepSize > 0 && minSeparation > 0) {
      if (separationUnit != UNIT_VALUE) {
        throw new IllegalStateException(
            String.format(
                EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE_UNIT, minSeparation, stepSize));
      }
      if (minSeparation < stepSize || !isMultipleOfStepSize(minSeparation)) {

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Re-apply values with Math.max(valueFrom, Math.min(valueTo, value)) after changing the range.
  2. Set the range (valueFrom/valueTo/stepSize) before setting values.
  3. When restoring persisted values, clamp them to the current range before calling setValues().
  4. Verify every value in a multi-thumb list is within bounds and sorted is handled internally, but bounds are your job.

Example fix

// before
slider.setValueFrom(0f);
slider.setValueTo(5f);
slider.setValues(7f); // 7 > valueTo -> crash on layout

// after
slider.setValueFrom(0f);
slider.setValueTo(10f);
slider.setValues(7f);
Defensive patterns

Strategy: validation

Validate before calling

static float clampToRange(float v, Slider slider) {
  return Math.max(slider.getValueFrom(), Math.min(slider.getValueTo(), v));
}
// slider.setValues(clampToRange(savedValue, slider));

Prevention

When it happens

Trigger: Calling setValues(...) with a value outside the range; calling setValueFrom/setValueTo to narrow the range while existing values (set earlier or from XML android:value) are now outside it; restoring state (onRestoreInstanceState) into a view whose range changed.

Common situations: Persisting the slider value (e.g. in SharedPreferences) and restoring it after the range was changed in a new app version; filtering UIs where the max price range shrinks based on another filter but the previous selection is kept.

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/4dac6d0919b88f47. Report an issue: GitHub.