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

The continuousModeTickCount(%s) must be greater than or equa

Error message

The continuousModeTickCount(%s) must be greater than or equal to 0

What it means

IllegalArgumentException thrown synchronously by setContinuousModeTickCount(int) when a negative count is passed. continuousModeTickCount draws purely visual ticks in continuous mode (stepSize 0); negative counts are meaningless and rejected immediately.

Source

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

  public int getContinuousModeTickCount() {
    return continuousModeTickCount;
  }

  /**
   * Sets the number of ticks to display in continuous mode. Default is 0.
   *
   * <p>This allows for showing purely visual ticks in continuous mode.
   *
   * <p>Setting this value to a negative value will result in an {@link IllegalArgumentException}.
   *
   * @param continuousModeTickCount The number of ticks that must be drawn in continuous mode count
   * @throws IllegalArgumentException If the continuous mode tick count is less than 0
   * @see #getContinuousModeTickCount()
   * @attr ref com.google.android.material.R.styleable#Slider_continuousModeTickCount
   */
  public void setContinuousModeTickCount(int continuousModeTickCount) {
    if (continuousModeTickCount < 0) {
      throw new IllegalArgumentException(
          String.format(EXCEPTION_ILLEGAL_CONTINUOUS_MODE_TICK_COUNT, continuousModeTickCount));
    }
    if (this.continuousModeTickCount != continuousModeTickCount) {
      this.continuousModeTickCount = continuousModeTickCount;
      dirtyConfig = true;
      postInvalidate();
    }
  }

  /**
   * Sets the custom thumb drawable which will be used for all value positions. Note that the custom
   * drawable provided will be resized to match the thumb radius set by {@link #setThumbRadius(int)}
   * or {@link #setThumbRadiusResource(int)}. Be aware that the image quality may be compromised
   * during resizing.
   *
   * @see #setCustomThumbDrawable(Drawable)
   * @see #setCustomThumbDrawablesForValues(int...)
   * @see #setCustomThumbDrawablesForValues(Drawable...)

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Use 0 to disable continuous-mode ticks instead of a negative sentinel.
  2. Math.max(0, computedTickCount) before calling the setter.
  3. Audit app:continuousModeTickCount in XML for negative literals.

Example fix

// before
slider.setContinuousModeTickCount(tickCount - 2); // -1 when tickCount == 1

// after
slider.setContinuousModeTickCount(Math.max(0, tickCount - 2));
Defensive patterns

Strategy: validation

Validate before calling

slider.setContinuousModeTickCount(Math.max(0, tickCount));

Prevention

When it happens

Trigger: Calling setContinuousModeTickCount(-1) or app:continuousModeTickCount with a negative value; deriving the count from data (e.g. item count - 1) that can go negative.

Common situations: Using -1 as a sentinel for 'no ticks' instead of 0; off-by-one computations like itemCount - 2 on a list of size 1.

Related errors


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