I\'m attempting to use Butter Knife to simplify creation of a custom BaseAdapter class. I\'m following the example here: http://jakewharton.github.io/butterknife/ under the \"A
For me it turned out that the ViewBinder
was not correctly refreshed. A clean project-build solved this issue.
Also check if you are inflating correct R.layout.
file. If not - necessary views are not found and this error occurs.
I had a similar problem with ButterKnife, but the reason was that I was inflating my fragment with the wrong layout.
(I know the question was already answered, but I decided to post my solution in case someone had the same issue)
Those who are still looking it happens if you are trying to bind wrong View type from XML in Java file it .
For example
You have TextView with id result
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_margin="3dp"
android:layout_weight="2"
android:background="#fff"
android:text="Calculator"
android:textSize="25sp" />
And you try to bind it with Button in java file
@BindView(R.id.result) Button result;
It gone crash you app.
Butterknife will throw exception for illegal casting of views as Unable to Inject View Error
Check if your @InjectView
s has correct type. I've used ImageView
instead of LinearLayout
. That might be your problem too.
Update:
Make sure you are not using ButterKnife's @OnItemClick(R.id.non_list_view)
with a non ListView
. I was using it for a android.support.v7.widget.RecyclerView
which was causing following exception:
java.lang.RuntimeException: Unable to inject views for MyFragment{... id=.... android:switcher:...}