java.lang.IllegalStateException Butterknife

你离开我真会死。 提交于 2019-12-05 06:32:50

Remove binding from base activity. When ButterKnife bind in base class, your layout not inflated yet.
Also you can add @Nullable annotation to field.

It's because your layout is not inflated yet. If you are using BaseActivity, do something like this :

public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(this.getLayoutContentViewID());
        ButterKnife.bind(this); //Configure Butterknife
    }

    public abstract int getLayoutContentViewID();

}

Next, in your MainActivity :

public class MainActivity extends BaseActivity {

    @BindView(R.id.main_activity_coordinator_layout) CoordinatorLayout coordinatorLayout;

    ...

    @Override
    public int getLayoutContentViewID() { return R.layout.activity_main; }
    ...

}
Shruti

Check your support Library version. I was getting the above error since i upgraded support library to 23 version. may be that is causing error.NavigationView get/find header layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!