Bound view is null when using Butterknife in fragment

ぃ、小莉子 提交于 2019-12-06 10:16:55

I had the same problem and I solved it adding the butterknife-compiler as apt. You can see it in the readme of ButterKnife

Be sure that you are implementing the dependency like this

dependencies {
    /* ... */
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

The annotationProcessor line is very important

My guess is that you are calling addLayoutToHolder before the ButterKnife binding has taken place, that's why layoutHolder is null. At what point of the lifecycle are you calling that method?

I found that after enabling the jack compiler options in the gradle with

...
jackOptions.enabled = true
...

somewhere butterknife fails to find the view binder and views are always null.

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