{"record":{"id":"6f90cd15e4fc0055","repo":"JakeWharton/butterknife","slug":"binddrawable-field-type-must-be-drawable","errorCode":null,"errorMessage":"@BindDrawable field type must be 'Drawable'. (","messagePattern":"@BindDrawable field type must be 'Drawable'\\. \\(","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"butterknife-reflect/src/main/java/butterknife/ButterKnife.java","lineNumber":531,"sourceCode":"  private static @Nullable Unbinder parseBindDrawable(Object target, Field field, View source) {\n    BindDrawable bindDrawable = field.getAnnotation(BindDrawable.class);\n    if (bindDrawable == null) {\n      return null;\n    }\n    validateMember(field);\n\n    int id = bindDrawable.value();\n    int tint = bindDrawable.tint();\n    Context context = source.getContext();\n\n    Class<?> fieldType = field.getType();\n    Object value;\n    if (fieldType == Drawable.class) {\n      value = tint != Constants.NO_RES_ID\n          ? Utils.getTintedDrawable(context, id, tint)\n          : ContextCompat.getDrawable(context, id);\n    } else {\n      throw new IllegalStateException(\"@BindDrawable field type must be 'Drawable'. (\"\n          + field.getDeclaringClass().getName()\n          + '.'\n          + field.getName()\n          + ')');\n    }\n    trySet(field, target, value);\n\n    return Unbinder.EMPTY;\n  }\n\n  private static @Nullable Unbinder parseBindFloat(Object target, Field field, View source) {\n    BindFloat bindInt = field.getAnnotation(BindFloat.class);\n    if (bindInt == null) {\n      return null;\n    }\n    validateMember(field);\n\n    int id = bindInt.value();","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-reflect/src/main/java/butterknife/ButterKnife.java#L513-L549","documentation":"Thrown by the reflection-based ButterKnife runtime when a field annotated with @BindDrawable is not declared as android.graphics.drawable.Drawable. The reflect binder resolves the annotation's resource (optionally tinted) and can only assign it to a Drawable-typed field; subtypes (e.g. a specific GradientDrawable) or other types are rejected because assignment is checked by exact class equality.","triggerScenarios":"Calling ButterKnife.bind(...) via butterknife-reflect on a class with a field such as `@BindDrawable(R.drawable.icon) GradientDrawable icon;` or `@BindDrawable(R.drawable.icon) Bitmap bitmap;` — anything where field.getType() != Drawable.class.","commonSituations":"Declaring the field as a concrete drawable subclass (VectorDrawable, GradientDrawable, BitmapDrawable) expecting polymorphic assignment, or annotating a Bitmap/ImageView field by mistake. The compiler path rejects this at build time; only the reflect path throws at runtime (typical in local JVM tests using butterknife-reflect).","solutions":["Declare the field as `Drawable` and cast to the concrete type after bind if a subclass API is needed.","If a Bitmap was intended, load it with BitmapFactory/BitmapFactory-decodeResource instead of @BindDrawable.","Prefer butterknife-compiler over butterknife-reflect in production builds so the error surfaces at compile time."],"exampleFix":"// before\n@BindDrawable(R.drawable.bg_card) GradientDrawable bg;\n\n// after\n@BindDrawable(R.drawable.bg_card) Drawable bg;\n// then: GradientDrawable g = (GradientDrawable) bg;","handlingStrategy":"type-guard","validationCode":"for (Field f : targetClass.getDeclaredFields()) {\n  if (f.isAnnotationPresent(BindDrawable.class)\n      && f.getType() != Drawable.class) {\n    throw new IllegalStateException(f + \" must be Drawable\");\n  }\n}","typeGuard":"static boolean isValidBindDrawableField(Field f) {\n  return !f.isAnnotationPresent(BindDrawable.class)\n      || f.getType() == Drawable.class;\n}","tryCatchPattern":null,"preventionTips":["Declare @BindDrawable fields exactly as android.graphics.drawable.Drawable.","Cast to a concrete drawable subclass after bind if subclass APIs are needed.","Use butterknife-compiler for compile-time validation in production builds."],"tags":["butterknife","reflection","annotation","field-type","binddrawable"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}