material-components/material-components-android · error · IllegalArgumentException

At least one value must be set

Error message

At least one value must be set

What it means

IllegalArgumentException thrown immediately by setValuesInternal() when setValues(List) or setValues(Float...) is called with an empty collection. A slider needs at least one thumb/value to render, so empty input is rejected synchronously (unlike the layout-time validations).

Source

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

   * <p>If the slider is in discrete mode (i.e. the tick increment value is greater than 0), the
   * values must be set to a value falls on a tick (i.e.: {@code value == valueFrom + x * stepSize},
   * where {@code x} is an integer equal to or greater than 0). If that is not the case, an {@link
   * IllegalStateException} will be thrown when the view is laid out.
   *
   * @param values An array of values to set.
   * @throws IllegalArgumentException If {@code values} is empty.
   */
  void setValues(@NonNull List<Float> values) {
    setValuesInternal(new ArrayList<>(values));
  }

  /**
   * This method assumes the list passed in is a copy. It is split out so we can call it from {@link
   * #setValues(Float...)} and {@link #setValues(List)}
   */
  private void setValuesInternal(@NonNull ArrayList<Float> values) {
    if (values.isEmpty()) {
      throw new IllegalArgumentException("At least one value must be set");
    }

    Collections.sort(values);

    if (this.values.size() == values.size()) {
      if (this.values.equals(values)) {
        return;
      }
    }

    this.values = values;
    dirtyConfig = true;
    updateDefaultThumbDrawables();
    // Only update the focused thumb index. The active thumb index will be updated on touch.
    focusedThumbIdx = 0;
    updateHaloHotspot();
    createLabelPool();
    dispatchOnChangedProgrammatically();

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Guard the call: only invoke setValues(list) when !list.isEmpty().
  2. Default to a single value (e.g. the current value or valueFrom) when the source list is empty.
  3. Fix the data source so at least one value is always produced.

Example fix

// before
slider.setValues(valuesFromDb); // crashes when list is empty

// after
if (!valuesFromDb.isEmpty()) {
  slider.setValues(valuesFromDb);
} else {
  slider.setValues(slider.getValueFrom());
}
Defensive patterns

Strategy: validation

Validate before calling

if (!values.isEmpty()) {
  slider.setValues(values);
} else {
  slider.setValues(slider.getValueFrom());
}

Prevention

When it happens

Trigger: slider.setValues() with an empty varargs call is a compile issue, but setValues(Collections.emptyList()) or setValues(emptyListFromApi) throws; passing a filtered list that happened to become empty.

Common situations: Loading thumb values from a database/network response that returns no rows; filter pipelines (map/filter) producing an empty list before setting values.

Related errors


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