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

indicatorColors cannot be empty when indicatorColor is not…

Error message

indicatorColors cannot be empty when indicatorColor is not used.

What it means

BaseProgressIndicatorSpec loads indicatorColor either as a single color or as an array resource (TYPE_REFERENCE). When the attribute is a reference to an array resource that is empty (zero entries), it throws IllegalArgumentException, since an indicator with no colors cannot render any stroke.

Solutions

  1. Populate the color array with at least one entry
  2. If a single color is intended, set app:indicatorColor="@color/x" directly instead of an array reference
  3. Add a resource-level sanity check for generated color arrays (fail build when empty)

Example fix

<!-- before: res/values/arrays.xml -->
<integer-array name="progress_colors"/>
<!-- after -->
<integer-array name="progress_colors">
  <item>@color/brand_primary</item>
  <item>@color/brand_secondary</item>
</integer-array>
Defensive patterns

Strategy: validation

Validate before calling

fun hasNonEmptyColorArray(context: Context, arrayRes: Int): Boolean {
    val arr = context.resources.getIntArray(arrayRes)
    return arr.isNotEmpty()
}

Try / catch

catch (e: IllegalArgumentException) { Log.e(TAG, "indicatorColor array empty; using single color", e); setSingleIndicatorColor() }

Prevention

When it happens

Trigger: Setting app:indicatorColor="@array/empty_colors" (an <integer-array> or similar with no <item> entries) on LinearProgressIndicator/CircularProgressIndicator; the TypedValue is TYPE_REFERENCE, getIntArray returns length 0, and the guard throws.

Common situations: Colors array generated from a build config or remote config that ends up empty; placeholder array resource left empty; wrong resource linked (points at an empty array).

Related errors


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

Appendix: source

Thrown at lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java:225

      return;
    }

    TypedValue indicatorColorValue =
        typedArray.peekValue(R.styleable.BaseProgressIndicator_indicatorColor);

    if (indicatorColorValue.type != TypedValue.TYPE_REFERENCE) {
      indicatorColors =
          new int[] {typedArray.getColor(R.styleable.BaseProgressIndicator_indicatorColor, -1)};
      return;
    }

    indicatorColors =
        context
            .getResources()
            .getIntArray(
                typedArray.getResourceId(R.styleable.BaseProgressIndicator_indicatorColor, -1));
    if (indicatorColors.length == 0) {
      throw new IllegalArgumentException(
          "indicatorColors cannot be empty when indicatorColor is not used.");
    }
  }

  /**
   * Loads the trackColor from attributes if existing; otherwise, uses the first value in {@link
   * BaseProgressIndicatorSpec#indicatorColors} applying the alpha value for disable items from
   * theme. This method doesn't recycle the {@link TypedArray} argument.
   *
   * @param context The current active context.
   * @param typedArray The TypedArray object of the attributes.
   */
  private void loadTrackColor(@NonNull Context context, @NonNull TypedArray typedArray) {
    if (typedArray.hasValue(R.styleable.BaseProgressIndicator_trackColor)) {
      trackColor = typedArray.getColor(R.styleable.BaseProgressIndicator_trackColor, -1);
      return;
    }

View on GitHub (pinned to ac7e18efee)