ButterKinfe.bind(this) @BindView时出现NullPointerException

来源:互联网 发布:淘宝介入能撤销吗 编辑:程序博客网 时间:2024/05/30 23:24

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'    }}apply plugin: 'com.neenbedankt.android-apt'dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        exclude group: 'com.android.support', module: 'support-annotations'
sync就不会出现空指针异常了!





原创粉丝点击