{"record":{"id":"6069f09f0f649c27","repo":"JakeWharton/butterknife","slug":"bindint-field-type-must-be-int","errorCode":null,"errorMessage":"@BindInt field type must be 'int'. (","messagePattern":"@BindInt field type must be 'int'\\. \\(","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"butterknife-reflect/src/main/java/butterknife/ButterKnife.java","lineNumber":627,"sourceCode":"    return Unbinder.EMPTY;\n  }\n\n  private static @Nullable Unbinder parseBindInt(Object target, Field field, View source) {\n    BindInt bindInt = field.getAnnotation(BindInt.class);\n    if (bindInt == null) {\n      return null;\n    }\n    validateMember(field);\n\n    int id = bindInt.value();\n    Resources resources = source.getContext().getResources();\n\n    Class<?> fieldType = field.getType();\n    Object value;\n    if (fieldType == int.class) {\n      value = resources.getInteger(id);\n    } else {\n      throw new IllegalStateException(\"@BindInt field type must be 'int'. (\"\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 parseBindString(Object target, Field field, View source) {\n    BindString bindString = field.getAnnotation(BindString.class);\n    if (bindString == null) {\n      return null;\n    }\n    validateMember(field);\n\n    int id = bindString.value();","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-reflect/src/main/java/butterknife/ButterKnife.java#L609-L645","documentation":"Thrown by the reflection-based ButterKnife runtime when a field annotated with @BindInt is not declared as primitive int. The binder resolves the integer resource with Resources.getInteger and only assigns to int.class; long, Integer, and float fields are rejected.","triggerScenarios":"ButterKnife.bind(...) via butterknife-reflect on a class with `@BindInt(R.int.max_count) Integer maxCount;`, `@BindInt(R.int.max_count) long maxCount;`, or `@BindInt(R.int.max_count) float maxCount;`.","commonSituations":"Boxing the field for nullability or API models, widening to long for counters, or annotating a dimen/float resource with @BindInt by mistake. Compile-time binder (butterknife-compiler) rejects this during build; only the reflect artifact throws at bind time.","solutions":["Change the field to primitive `int`.","If a long/Integer is required downstream, keep the int field and convert after bind.","For non-integer resources use @BindFloat/@BindDimen; for compile-time safety switch to butterknife-compiler."],"exampleFix":"// before\n@BindInt(R.int.anim_duration_ms) Long durationMs;\n\n// after\n@BindInt(R.int.anim_duration_ms) int durationMs;","handlingStrategy":"type-guard","validationCode":"for (Field f : targetClass.getDeclaredFields()) {\n  if (f.isAnnotationPresent(BindInt.class) && f.getType() != int.class) {\n    throw new IllegalStateException(f + \" must be int\");\n  }\n}","typeGuard":"static boolean isValidBindIntField(Field f) {\n  return !f.isAnnotationPresent(BindInt.class) || f.getType() == int.class;\n}","tryCatchPattern":null,"preventionTips":["Use primitive `int`, never Integer/long.","Reserve @BindInt for <integer> resources; @BindDimen/@BindFloat for others.","Use butterknife-compiler to fail at compile time."],"tags":["butterknife","reflection","annotation","field-type","bindint"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}