{"record":{"id":"667962736d39c40e","repo":"JakeWharton/butterknife","slug":"required-view-with-id-for-was-not-found","errorCode":null,"errorMessage":"Required view '{}' with ID {} for {} was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.","messagePattern":"Required view '(.+?)' with ID (.+?) for (.+?) was not found\\. If this view is optional add '@Nullable' \\(fields\\) or '@Optional' \\(methods\\) annotation\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"butterknife-runtime/src/main/java/butterknife/internal/Utils.java","lineNumber":84,"sourceCode":"\n  @SafeVarargs\n  public static <T> List<T> listFilteringNull(T... views) {\n    return new ImmutableList<>(arrayFilteringNull(views));\n  }\n\n  public static <T> T findOptionalViewAsType(View source, @IdRes int id, String who,\n      Class<T> cls) {\n    View view = source.findViewById(id);\n    return castView(view, id, who, cls);\n  }\n\n  public static View findRequiredView(View source, @IdRes int id, String who) {\n    View view = source.findViewById(id);\n    if (view != null) {\n      return view;\n    }\n    String name = getResourceEntryName(source, id);\n    throw new IllegalStateException(\"Required view '\"\n        + name\n        + \"' with ID \"\n        + id\n        + \" for \"\n        + who\n        + \" was not found. If this view is optional add '@Nullable' (fields) or '@Optional'\"\n        + \" (methods) annotation.\");\n  }\n\n  public static <T> T findRequiredViewAsType(View source, @IdRes int id, String who,\n      Class<T> cls) {\n    View view = findRequiredView(source, id, who);\n    return castView(view, id, who, cls);\n  }\n\n  public static <T> T castView(View view, @IdRes int id, String who, Class<T> cls) {\n    try {\n      return cls.cast(view);","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-runtime/src/main/java/butterknife/internal/Utils.java#L66-L102","documentation":"Thrown by Utils.findRequiredView (used by generated/reflect bindings for non-@Nullable @BindView fields and non-@Optional listener methods) when findViewById for the requested ID returns null on the bound source view hierarchy. The message includes the resource entry name, numeric ID, and the 'who' description (class.field), and tells you the escape hatches.","triggerScenarios":"ButterKnife.bind(this) where @BindView(R.id.title) is required, but the content view inflated (setContentView / fragment layout) has no view with that ID — wrong layout inflated, ID only in a different flavor/build variant layout, child view not yet inflated, or binding on the wrong source (ButterKnife.bind(this, drawerHeader) etc.).","commonSituations":"Landscape/night/flavor layout variants missing a view present in the default layout; multi-pane vs single-pane layout swap; binding before the view exists (bind before setContentView, or in a fragment before onViewCreated); binding a header/footer row layout where the ID belongs to the row layout but bind was called on the item container. Library consumers commonly hit it after renaming or removing an ID in XML while annotations still reference it.","solutions":["Verify the inflated layout actually declares the ID; align flavor/orientation variants that omit it.","Move ButterKnife.bind into onCreateView/onViewCreated (fragment) or after setContentView (activity).","If the view is genuinely optional, annotate the field @Nullable (butterknife.@Nullable) or the method @Optional so a missing view is skipped."],"exampleFix":"// before\n@BindView(R.id.subtitle) TextView subtitle; // absent in landscape layout\n\n// after\n@Nullable @BindView(R.id.subtitle) TextView subtitle; // null-safe in landscape","handlingStrategy":"validation","validationCode":"// Before bind: confirm the required view exists\nView v = sourceView.findViewById(R.id.subtitle);\nif (v == null && !fieldIsAnnotatedNullable) {\n  // align layout, bind later, or mark @Nullable\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind after the view hierarchy exists (post-setContentView / onViewCreated).","Keep layout variants (landscape, flavors) in sync for every bound ID.","Mark genuinely optional fields @Nullable and methods @Optional instead of catching the exception."],"tags":["butterknife","view-lookup","layout","resource-id","nullable"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}