您的位置:首页 > Web前端

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

2017-06-12 14:35 447 查看
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就不会出现空指针异常了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐