{"record":{"id":"3763b2b5f84d8b3d","repo":"JakeWharton/butterknife","slug":"binddimen-field-type-must-be-int-or-float","errorCode":null,"errorMessage":"@BindDimen field type must be 'int' or 'float'. (","messagePattern":"@BindDimen field type must be 'int' or 'float'\\. \\(","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"butterknife-reflect/src/main/java/butterknife/ButterKnife.java","lineNumber":502,"sourceCode":"\n  private static @Nullable Unbinder parseBindDimen(Object target, Field field, View source) {\n    BindDimen bindDimen = field.getAnnotation(BindDimen.class);\n    if (bindDimen == null) {\n      return null;\n    }\n    validateMember(field);\n\n    int id = bindDimen.value();\n    Resources resources = source.getContext().getResources();\n\n    Class<?> fieldType = field.getType();\n    Object value;\n    if (fieldType == int.class) {\n      value = resources.getDimensionPixelSize(id);\n    } else if (fieldType == float.class) {\n      value = resources.getDimension(id);\n    } else {\n      throw new IllegalStateException(\"@BindDimen field type must be 'int' or 'float'. (\"\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 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();","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-reflect/src/main/java/butterknife/ButterKnife.java#L484-L520","documentation":"Thrown by the reflection-based ButterKnife runtime when a field annotated with @BindDimen is declared with a type other than int or float. The reflect binder inspects field.getType() at bind time and only knows how to produce a dimension pixel size (int) or a raw dimension (float); any other declared type is a programming error in the annotated class.","triggerScenarios":"Calling ButterKnife.bind(target, source) (butterknife-reflect) on a class that has a field like `@BindDimen(R.dimen.foo) long dimen;` or `@BindDimen(R.dimen.foo) Double dimen;` — i.e. the declared field type is not exactly int.class or float.class (boxed types also fail).","commonSituations":"Developer boxes the primitive (Integer/Double/Float), uses long for large dimensions, or copies a @BindDimen declaration onto an existing field of a wider type during refactoring. Note the annotation processor (butterknife-compiler) rejects this at compile time, so it appears only when using the butterknife-reflect artifact (e.g. in unit tests or instant-run setups).","solutions":["Change the field declaration to `int` (getDimensionPixelSize, dp-accurate pixel size) or `float` (getDimension, raw value).","If the boxed type is intentional, keep an int/float field and assign it to the wrapper separately after bind.","Switch from butterknife-reflect to butterknife-compiler so this mistake fails at compile time instead of runtime."],"exampleFix":"// before\n@BindDimen(R.dimen.activity_margin) Long margin;\n\n// after\n@BindDimen(R.dimen.activity_margin) float margin;","handlingStrategy":"type-guard","validationCode":"// Before bind: assert every @BindDimen field is int or float\nfor (Field f : targetClass.getDeclaredFields()) {\n  if (f.isAnnotationPresent(BindDimen.class)) {\n    Class<?> t = f.getType();\n    if (t != int.class && t != float.class) {\n      throw new IllegalStateException(f + \" must be int or float\");\n    }\n  }\n}","typeGuard":"static boolean isValidBindDimenField(Field f) {\n  if (!f.isAnnotationPresent(BindDimen.class)) return true;\n  Class<?> t = f.getType();\n  return t == int.class || t == float.class;\n}","tryCatchPattern":null,"preventionTips":["Always declare @BindDimen fields as primitive int or float — never boxed types.","Prefer butterknife-compiler so this class of error fails at compile time.","In Kotlin use `int`/`float` (not Int?/Float?/Double)."],"tags":["butterknife","reflection","annotation","field-type","binddimen"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}