美文网首页
ButterKnife.bind(this),@BindView

ButterKnife.bind(this),@BindView

作者: Android小学生_Joe | 来源:发表于2017-06-12 14:48 被阅读0次

ButterKnife版本 8.4.0,@BindView会出现空指针异常,然后我把@BindView换成了findViewById还是报错

网上逛论坛发现,ButterKnife 8.0.1的很多使用者都会出现这种错误,究竟为什么会出现这种错误呢?

原因貌似是我们只是简单的在build,gradle添加了声明

compile 'com.jakewharton:butterknife:8.0.1'

除此之外还要在app下的build.gradle文件中添加一些配置:

添加apt声明

compile'com.jakewharton:butterknife:8.4.0'apt'com.jakewharton:butterknife-compiler:8.4.0'

在依赖前面加上buildscript声明

buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath'com.neenbedankt.gradle.plugins:android-apt:1.8'}}applyplugin:'com.neenbedankt.android-apt'dependencies {    compile fileTree(dir:'libs',include: ['*.jar'])    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        excludegroup:'com.android.support',module:'support-annotations'

sync就不会出现空指针异常了!

相关文章

网友评论

      本文标题:ButterKnife.bind(this),@BindView

      本文链接:https://www.haomeiwen.com/subject/ttplqxtx.html