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

indicatorColors cannot be empty when indicatorColor is not u

Error message

indicatorColors cannot be empty when indicatorColor is not used.

What it means

LoadingIndicatorSpec parses the indicatorColor attribute: when it points to a color everything is fine, but when it points to an array resource (@array/... via TYPE_REFERENCE) the array is read with getIntArray. An empty array resource leaves the indicator with no colors to draw, which is unrecoverable, so initialization throws IllegalArgumentException.

Source

Thrown at lib/java/com/google/android/material/loadingindicator/LoadingIndicatorSpec.java:109

          };
      return;
    }

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

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

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

  /**
   * Sets the scale specs to fit the given bound of the {@link LoadingIndicatorDrawable}.
   *
   * @param scaleToFit The new scaleToFit value.
   */
  public void setScaleToFit(boolean scaleToFit){
    this.scaleToFit = scaleToFit;
  }
}

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Populate the referenced integer-array with at least one color: <integer-array name="indicator_colors"><item>@color/blue</item></integer-array>.
  2. Or point app:indicatorColor at a single color instead of an array reference.
  3. Audit all build variants/flavors to ensure the array resource is non-empty everywhere it resolves.

Example fix

<!-- before -->
<integer-array name="indicator_colors" />
<com...LoadingIndicator app:indicatorColor="@array/indicator_colors" ... />

<!-- after -->
<integer-array name="indicator_colors">
  <item>@color/m3_sys_color_primary</item>
</integer-array>
Defensive patterns

Strategy: validation

Validate before calling

int[] colors = context.getResources().getIntArray(R.array.indicator_colors);
if (colors == null || colors.length == 0) {
  colors = new int[] { ContextCompat.getColor(context, R.color.default_indicator) };
}
// then set programmatically instead of relying on the attribute

Prevention

When it happens

Trigger: Setting app:indicatorColor="@array/empty_colors" (or any <integer-array> with zero items) on a LoadingIndicator (CircularProgressIndicator-style loading spinner styled with LoadingIndicator attributes); referencing an array resource that resolves to empty in some build variant/flavor.

Common situations: Shared color arrays defined per-flavor where one flavor ships an empty list; typos pointing at the wrong array resource; arrays built by resource merging that end up empty.

Related errors


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