material-components/material-components-android · error · IllegalStateException
valueFrom(%s) must be smaller than valueTo(%s)
Error message
valueFrom(%s) must be smaller than valueTo(%s)
What it means
Thrown by validateValues() when valueFrom is greater than or equal to valueTo, which would produce an empty or inverted slider range. Like the other slider validations it fires when the view is laid out, not when the setter runs, so a bad pair can be set without error and crash later.
Source
Thrown at lib/java/com/google/android/material/slider/BaseSlider.java:745
return Math.abs(Math.round(result) - result) < THRESHOLD;
}
private void validateStepSize() {
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(View on GitHub (pinned to ac7e18efee)
Solutions
- Ensure valueFrom < valueTo strictly; equal values are also rejected.
- Clamp/sanitize dynamic bounds before applying: if (min >= max) max = min + 1 (or skip the update).
- To visually reverse a slider, keep valueFrom < valueTo and use android:supportsRtl / layoutDirection, not swapped values.
- Check the ordering every time either bound is changed programmatically.
Example fix
// before slider.setValueFrom(10f); slider.setValueTo(10f); // equal -> IllegalStateException on layout // after slider.setValueFrom(0f); slider.setValueTo(10f);
Defensive patterns
Strategy: validation
Validate before calling
static boolean rangeValid(float from, float to) { return from < to; }
// if (rangeValid(min, max)) { slider.setValueFrom(min); slider.setValueTo(max); } Prevention
- Treat (valueFrom, valueTo) as an inseparable pair; update both from one sanitized source.
- Skip the update when a dynamic range arrives inverted or empty instead of applying it.
- Never swap from/to to reverse a slider; use RTL layout direction.
When it happens
Trigger: Calling setValueTo(v) with v <= valueFrom, or setValueFrom(v) with v >= valueTo; loading app:valueFrom/app:valueTo from XML with equal or swapped values; building an RTL-localized 'reversed' slider by swapping from/to instead of using layout direction.
Common situations: Data-driven sliders where both bounds come from a config or API and the API occasionally returns min == max or min > max; copy-paste XML where only one bound was updated; attempting to invert a slider by swapping the values.
Related errors
- Slider value(%s) must be greater or equal to valueFrom(%s),
- minSeparation(%s) must be greater or equal to 0
- minSeparation(%s) cannot be set as a dimension when using st
- minSeparation(%s) must be greater or equal and a multiple of
- %1$s requires a value for the %2$s attribute to be set in yo
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/48206fbfa60ae9a8.
Report an issue: GitHub.