{"record":{"id":"1eb949c0a1bcb849","repo":"JakeWharton/butterknife","slug":"bindfloat-field-type-must-be-float","errorCode":null,"errorMessage":"@BindFloat field type must be 'float'. (","messagePattern":"@BindFloat field type must be 'float'\\. \\(","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"butterknife-reflect/src/main/java/butterknife/ButterKnife.java","lineNumber":557,"sourceCode":"    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();\n    Context context = source.getContext();\n\n    Class<?> fieldType = field.getType();\n    Object value;\n    if (fieldType == float.class) {\n      value = Utils.getFloat(context, id);\n    } else {\n      throw new IllegalStateException(\"@BindFloat field type must be '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 parseBindFont(Object target, Field field, View source) {\n    BindFont bindFont = field.getAnnotation(BindFont.class);\n    if (bindFont == null) {\n      return null;\n    }\n    validateMember(field);\n\n    int id = bindFont.value();","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-reflect/src/main/java/butterknife/ButterKnife.java#L539-L575","documentation":"Thrown by the reflection-based ButterKnife runtime when a field annotated with @BindFloat is not declared as primitive float. The binder reads the resource with Utils.getFloat and can only assign a float; doubles, boxed Floats, and ints are all rejected by the exact field.getType() == float.class check.","triggerScenarios":"ButterKnife.bind(...) via butterknife-reflect on a class containing `@BindFloat(R.dimen.ratio) double ratio;`, `@BindFloat(R.dimen.ratio) Float ratio;`, or `@BindFloat(R.dimen.ratio) int ratio;`.","commonSituations":"Using double for precision math and expecting implicit widening, boxing the value for an ORM/JSON model, or annotating a resource that was assumed to be an integer. The annotation processor catches this at compile time; the reflect artifact (common in unit tests) defers it to runtime.","solutions":["Change the field to primitive `float`.","If double precision is required afterwards, keep the float field and copy into a double after bind.","Use @BindInt for integer resources or switch to butterknife-compiler for compile-time validation."],"exampleFix":"// before\n@BindFloat(R.dimen.aspect) Double aspect;\n\n// after\n@BindFloat(R.dimen.aspect) float aspect;","handlingStrategy":"type-guard","validationCode":"for (Field f : targetClass.getDeclaredFields()) {\n  if (f.isAnnotationPresent(BindFloat.class) && f.getType() != float.class) {\n    throw new IllegalStateException(f + \" must be float\");\n  }\n}","typeGuard":"static boolean isValidBindFloatField(Field f) {\n  return !f.isAnnotationPresent(BindFloat.class) || f.getType() == float.class;\n}","tryCatchPattern":null,"preventionTips":["Use primitive `float`, never Float or double.","Remember @BindFloat requires a float-format resource (`<item format=\"float\">`).","Use butterknife-compiler to catch type mistakes at build time."],"tags":["butterknife","reflection","annotation","field-type","bindfloat"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}