{"record":{"id":"87a6567c63f0ff98","repo":"material-components/material-components-android","slug":"1-s-requires-a-value-for-the-2-s-attribute-to-be","errorCode":null,"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).","messagePattern":"%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\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"lib/java/com/google/android/material/resources/MaterialAttributes.java","lineNumber":81,"sourceCode":"  @NonNull\n  public static TypedValue resolveTypedValueOrThrow(\n      @NonNull View componentView, @AttrRes int attributeResId) {\n    return resolveTypedValueOrThrow(\n        componentView.getContext(), attributeResId, componentView.getClass().getCanonicalName());\n  }\n\n  @NonNull\n  public static TypedValue resolveTypedValueOrThrow(\n      @NonNull Context context,\n      @AttrRes int attributeResId,\n      @NonNull String errorMessageComponent) {\n    TypedValue typedValue = resolve(context, attributeResId);\n    if (typedValue == null) {\n      String errorMessage =\n          \"%1$s requires a value for the %2$s attribute to be set in your app theme. \"\n              + \"You can either set the attribute in your theme or \"\n              + \"update your theme to inherit from Theme.MaterialComponents (or a descendant).\";\n      throw new IllegalArgumentException(\n          String.format(\n              errorMessage,\n              errorMessageComponent,\n              context.getResources().getResourceName(attributeResId)));\n    }\n    return typedValue;\n  }\n\n  /**\n   * Returns the {@link TypedValue} for the provided {@code attributeResId}.\n   *\n   * @throws IllegalArgumentException if the attribute is not present in the current theme.\n   */\n  public static int resolveOrThrow(\n      @NonNull Context context,\n      @AttrRes int attributeResId,\n      @NonNull String errorMessageComponent) {\n    return resolveTypedValueOrThrow(context, attributeResId, errorMessageComponent).data;","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/resources/MaterialAttributes.java#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Change the theme (activity or application) to inherit from Theme.MaterialComponents or Theme.Material3, e.g. parent=\"Theme.Material3.DayNight.NoActionBar\".","Or explicitly declare the missing attribute named in the exception message inside your theme, e.g. <item name=\"colorPrimary\">...</item>.","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.","Update the component's XML tools:theme or layout-level android:theme to a Material theme if only one subtree needs it."],"exampleFix":"<!-- before -->\n<style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\"> ... </style>\n\n<!-- after -->\n<style name=\"AppTheme\" parent=\"Theme.Material3.DayNight.NoActionBar\"> ... </style>","handlingStrategy":"validation","validationCode":"TypedValue tv = new TypedValue();\nboolean hasMaterialTheme = context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorPrimary}).hasValue(0);\nif (!hasMaterialTheme) {\n  context = new ContextThemeWrapper(context, R.style.Theme_Material3_DayNight_NoActionBar);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make every activity/dialog theme inherit from Theme.MaterialComponents or Theme.Material3 at the app level.","Never inflate Material widgets with applicationContext; use the activity context or a ContextThemeWrapper.","Wrap dialog contexts: new MaterialAlertDialogBuilder(new ContextThemeWrapper(ctx, themeRes))."],"tags":["android","material-components","theme","xml","configuration"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}