material-components/material-components-android · critical · IllegalArgumentException

%1$s requires a value for the %2$s attribute to be set in yo

Error message

%1$s requires a value for the %2$s attribute to be set in your app theme. You can either set the attribute in your theme or update your theme to inherit from Theme.MaterialComponents (or a descendant).

What it means

MaterialAttributes.resolveTypedValueOrThrow() throws IllegalArgumentException when a required theme attribute cannot be resolved in the current theme. Material widgets use this to insist that apps either set the attribute themselves or use a MaterialComponents/Material3 theme; the message names the component and the missing attribute. This is the canonical 'app is not using a Material theme' crash.

Source

Thrown at lib/java/com/google/android/material/resources/MaterialAttributes.java:81

  @NonNull
  public static TypedValue resolveTypedValueOrThrow(
      @NonNull View componentView, @AttrRes int attributeResId) {
    return resolveTypedValueOrThrow(
        componentView.getContext(), attributeResId, componentView.getClass().getCanonicalName());
  }

  @NonNull
  public static TypedValue resolveTypedValueOrThrow(
      @NonNull Context context,
      @AttrRes int attributeResId,
      @NonNull String errorMessageComponent) {
    TypedValue typedValue = resolve(context, attributeResId);
    if (typedValue == null) {
      String errorMessage =
          "%1$s requires a value for the %2$s attribute to be set in your app theme. "
              + "You can either set the attribute in your theme or "
              + "update your theme to inherit from Theme.MaterialComponents (or a descendant).";
      throw new IllegalArgumentException(
          String.format(
              errorMessage,
              errorMessageComponent,
              context.getResources().getResourceName(attributeResId)));
    }
    return typedValue;
  }

  /**
   * Returns the {@link TypedValue} for the provided {@code attributeResId}.
   *
   * @throws IllegalArgumentException if the attribute is not present in the current theme.
   */
  public static int resolveOrThrow(
      @NonNull Context context,
      @AttrRes int attributeResId,
      @NonNull String errorMessageComponent) {
    return resolveTypedValueOrThrow(context, attributeResId, errorMessageComponent).data;

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Change the theme (activity or application) to inherit from Theme.MaterialComponents or Theme.Material3, e.g. parent="Theme.Material3.DayNight.NoActionBar".
  2. Or explicitly declare the missing attribute named in the exception message inside your theme, e.g. <item name="colorPrimary">...</item>.
  3. Check the context: preview tools, dialogs, and inflations with applicationContext or a wrapped non-Material context are common culprits — pass a themed activity context or wrap with ContextThemeWrapper.
  4. Update the component's XML tools:theme or layout-level android:theme to a Material theme if only one subtree needs it.

Example fix

<!-- before -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> ... </style>

<!-- after -->
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar"> ... </style>
Defensive patterns

Strategy: validation

Validate before calling

TypedValue tv = new TypedValue();
boolean hasMaterialTheme = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorPrimary}).hasValue(0);
if (!hasMaterialTheme) {
  context = new ContextThemeWrapper(context, R.style.Theme_Material3_DayNight_NoActionBar);
}

Prevention

When it happens

Trigger: Inflating a Material component (e.g. Chips, MaterialButton, TextInputLayout via MaterialComponentsViewInflater) inside an Activity/Fragment/Dialog whose theme inherits from Theme.AppCompat or android:Theme.* instead of Theme.MaterialComponents / Theme.Material3, so attributes like colorPrimary, colorSecondary, or a widget-specific attribute resolve to null.

Common situations: Setting a new activity's theme to a plain AppCompat theme while the manifest/application still uses MaterialComponentsViewInflater; using a Material component inside a dialog styled with a non-Material theme; adding a Material3 widget while the theme parent is Theme.MaterialComponents (or vice versa after upgrading to Material3).

Related errors


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