butterknife
butterknife copied to clipboard
Binding Not Found
I am getting numerous null pointer exceptions from ButterKnife failing to bind views into Java. I guess the binding might not be being generated? Please can you help me find steps to fix this issue?
From the Logs:
D/ButterKnife: Looking up binding for com.littlesparkshospital.littletrial.activities.MainActivity
D/ButterKnife: Not found. Trying superclass androidx.appcompat.app.AppCompatActivity
XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/family_image"
android:layout_toRightOf="@+id/setting_image"
android:id="@+id/map_container">
Java:
@BindView(R.id.map_container)
RelativeLayout mapContainer;
I am using version 10.1.0 of butterknife:
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
It looks like the MainActivity_ViewBinding.java is being generated as I would have expected, so I guess that the library can't find this generated code at runtime? :/
// Generated code from Butter Knife. Do not modify!
package com.littlesparkshospital.littletrial.activities;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.CallSuper;
import androidx.annotation.UiThread;
import butterknife.Unbinder;
import butterknife.internal.DebouncingOnClickListener;
import butterknife.internal.Utils;
import com.littlesparkshospital.littletrial.R;
import java.lang.IllegalStateException;
import java.lang.Override;
public class MainActivity_ViewBinding implements Unbinder {
private MainActivity target;
private View view7f090184;
private View view7f090080;
@UiThread
public MainActivity_ViewBinding(MainActivity target) {
this(target, target.getWindow().getDecorView());
}
@UiThread
public MainActivity_ViewBinding(final MainActivity target, View source) {
this.target = target;
View view;
target.mapContainer = Utils.findRequiredViewAsType(source, R.id.map_container, "field 'mapContainer'", RelativeLayout.class);
view = Utils.findRequiredView(source, R.id.setting_image, "field 'setting_image' and method 'openSettings'");
Same problem, any solution?
Did you call ButterKnife.bind(xxx) after inflate?
setContentView(R.layout.activity_login);
unbinder = ButterKnife.bind(this);
绑定一会空,一会不空,我太难了。
This is weird, I get the same after upgrading from 8.7.0 to 10.2.0 and migrating to AndroidX.
Edit: Note there is an issue located here on this. #1571