When I try to bind my views with Butterknife I get this IllegalStateException
after every time I call ButterKnife.bind(this, fragmentView!!)
method.
For example:
//...BindView section
@BindView(R.id.logoutButton)
lateinit var logoutButton: View
@BindView(R.id.closeSession)
lateinit var closeSessionButton: View
@BindView(R.id.settings)
lateinit var settingsButton: View
And I get this:
java.lang.IllegalStateException: Required view login with ID 2131362018 for field logoutButton was not found. If this view is optional add @Nullable (fields) or @Optional (methods) annotation.
The point is that I DIDN'T BIND the 'login' view as the exception says. I bounded 'logutButton'. I did have 'login' view, but in the other fragment which has no connection to fragment where the exception appears.
And this happening in every fragment, activity, or adapter or something else which needs binding views with butterknife.
And every time Butterknife tries to bind, an absolutely random view for the field that comes first in declaration order (only first @BindView
annotation affected, the next annotation are fine)
I'm using @Nullable
annotation and it's helping perfectly (even after I deleted @Nullable
annotation - fragment works fine). But I have lots of fragments and activities, so I can't check all of them and add the @Nullable
annotation.
How I can find the source of this problem so that it never happens again?
This is how i solved this:
Build -> Clean Project
And everything fine!