butterknife icon indicating copy to clipboard operation
butterknife copied to clipboard

Strange behaviour of `ButterKnife.bind(this, rootView)`

Open miPlodder opened this issue 5 years ago • 5 comments

Error Log - java.lang.IllegalStateException: Required view 'expanded_menu' with ID 2131362009 for method 'addGroup' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.

onCreateView() { ButterKnife.bind(this, rootView) }

onViewCreated() { ButterKnife.bind(this, rootView); }

I have to remove this line from onCreateView() to onViewCreated() to remove the error mentioned above. But after a few runs from Studio, I have to remove this line from onViewCreated() and write it back to onCreateView() to remove the error mentioned above.

And the loop continues, is there any permanent place where I should keep it?

miPlodder avatar Jul 04 '19 09:07 miPlodder

Is there any chance that you have this in your dependencies section:

if (properties.containsKey('android.injected.invoked.from.ide')) {
    implementation 'com.jakewharton:butterknife-reflect:10.1.0'
} else {
   implementation 'com.jakewharton:butterknife:10.1.0'
   kapt 'com.jakewharton:butterknife-compiler:10.1.0'
}

? This seems like a problem with butterknife-reflect library

scana avatar Jul 12 '19 14:07 scana

Are you call Butterknife.bind() after inflate()? @miPlodder

JantHsueh avatar Jul 29 '19 03:07 JantHsueh

We are facing exactly the same error on the project which is fixed by clean and rebuild but it is not a solution. And we do not have reflect library dependency in our app.

yevhenii-rechun avatar Aug 15 '19 21:08 yevhenii-rechun

Exactly the same issue here... I build app and have crash due to this error. But after clean it works once and build again - crash...

I think it's related with change of class R by android studio, but generated adapter isn't refreshed so it has previous id which already changed.

miszmaniac avatar Oct 17 '19 20:10 miszmaniac

Can you provide a test case or executable sample that demonstrates the problem?

JakeWharton avatar Apr 11 '20 04:04 JakeWharton