JakeWharton/butterknife · error · IllegalStateException
@BindBitmap field type must be 'Bitmap'. (
Error message
@BindBitmap field type must be 'Bitmap'. (
What it means
@BindBitmap decodes a resource into an android.graphics.Bitmap via BitmapFactory.decodeResource, so parseBindBitmap requires the field type to be exactly Bitmap. Any other type — Drawable, ImageView, Bitmaap subclasses like BitmapDrawable — throws this IllegalStateException at bind time.
Source
Thrown at butterknife-reflect/src/main/java/butterknife/ButterKnife.java:420
return Unbinder.EMPTY;
}
private static @Nullable Unbinder parseBindBitmap(Object target, Field field, View source) {
BindBitmap bindBitmap = field.getAnnotation(BindBitmap.class);
if (bindBitmap == null) {
return null;
}
validateMember(field);
int id = bindBitmap.value();
Resources resources = source.getContext().getResources();
Object value;
Class<?> fieldType = field.getType();
if (fieldType == Bitmap.class) {
value = BitmapFactory.decodeResource(resources, id);
} else {
throw new IllegalStateException("@BindBitmap field type must be 'Bitmap'. ("
+ field.getDeclaringClass().getName()
+ '.'
+ field.getName()
+ ')');
}
trySet(field, target, value);
return Unbinder.EMPTY;
}
private static @Nullable Unbinder parseBindBool(Object target, Field field, View source) {
BindBool bindBool = field.getAnnotation(BindBool.class);
if (bindBool == null) {
return null;
}
validateMember(field);
int id = bindBool.value();View on GitHub (pinned to fcdebedf32)
Solutions
- Declare the field as `Bitmap`: `@BindBitmap(R.drawable.logo) Bitmap logo;`
- If you need a Drawable, use @BindDrawable instead
- If you need the ImageView, use @BindView and load the bitmap into it separately
Example fix
// before @BindBitmap(R.drawable.logo) Drawable logo; // after @BindBitmap(R.drawable.logo) Bitmap logo;
Defensive patterns
Strategy: type-guard
Validate before calling
if (field.getType() != Bitmap.class) {
throw new IllegalStateException("@BindBitmap field must be Bitmap: " + field);
} Type guard
static boolean isBitmapField(Field f) {
return f.getType() == android.graphics.Bitmap.class;
} Prevention
- Type @BindBitmap fields exactly as Bitmap; use @BindDrawable for Drawables
- Bind the ImageView with @BindView and set the bitmap separately
When it happens
Trigger: `@BindBitmap(R.drawable.logo) Drawable logo;` or `@BindBitmap(...) ImageView logo;` — field types that are not Bitmap.
Common situations: Confusing bitmap resources with drawable resources; intending @BindDrawable for a Drawable field; annotating the ImageView that displays the image instead of a Bitmap field.
Related errors
- @BindView fields must extend from View or be an interface. (
- @BindViews must be a List or array. (
- @BindViews List or array type must extend from View or be an
- @BindAnim field type must be 'Animation'. (
- @BindArray field type must be one of: String[], int[], CharS
AI-assisted analysis of JakeWharton/butterknife@fcdebedf32 (2026-08-14).
Data as JSON: /api/errors/f92b92946d4d368e.
Report an issue: GitHub.