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

minSeparation(%s) cannot be set as a dimension when using st

Error message

minSeparation(%s) cannot be set as a dimension when using stepSize(%s)

What it means

Thrown by validateMinSeparation() when a dimension-based min separation (setMinSeparationDimension / separationUnit != UNIT_VALUE) is combined with a positive stepSize. In discrete mode ticks are value-based, so a pixel/dp separation cannot be reconciled with value steps, and the library rejects the combination at layout time.

Source

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

        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)) {
        throw new IllegalStateException(
            String.format(
                EXCEPTION_ILLEGAL_MIN_SEPARATION_STEP_SIZE, minSeparation, stepSize, stepSize));
      }
    }
  }

  private void warnAboutFloatingPointError() {
    if (stepSize == 0) {
      // Only warn if slider uses a step value.
      return;
    }

    if ((int) stepSize != stepSize) {

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Use setMinSeparation(value) (UNIT_VALUE) instead of the dimension variant when stepSize > 0.
  2. Or remove stepSize (set it to 0) if the dimension-based separation must be kept.
  3. Pick a value-unit separation that is >= stepSize and a multiple of it (see error 145).

Example fix

// before
slider.setStepSize(1f);
slider.setMinSeparationDimension(16f, SliderSeparationUnit.PIXEL); // throws on layout

// after
slider.setStepSize(1f);
slider.setMinSeparation(2f); // value units, multiple of stepSize
Defensive patterns

Strategy: validation

Validate before calling

if (slider.getStepSize() > 0f) {
  slider.setMinSeparation(2f);          // value units
} else {
  slider.setMinSeparationDimension(dp, SliderSeparationUnit.DP);
}

Prevention

When it happens

Trigger: Calling setMinSeparationDimension(ratioOrDimension) (or setting app:minSeparation as a dimension) on a slider that also has stepSize > 0.

Common situations: Reusing a range-slider styling block (with dp-based minSeparation) on a slider that was later switched to discrete ticks; XML copied from a continuous slider template into a discrete one.

Related errors


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