您的位置:首页 > Web前端

ButterKnife 8.0.1 @BindView 失败,nullpointerexception

2017-05-09 21:26 447 查看
ButterKnife 8.0.1 @BindView 失败,空指针异常,跟踪进去,发现是XXXFragment的 XXXFragment$$ViewBinder 的类没有生成。经过google。发现了解决方案。记录一下。

ButterKnife8.0.1 not working

Per the readme, you need to include the 
butterknife-compiler
 inorder for the generated code to be produced automatically:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}
Without this there is no generated code to be loaded and thus none of the fields get set.You can verify ButterKnife is working by calling 
ButterKnife.setDebug(true)
 andlooking in Logcat简单的说呢。就是之前只加了
compile 'com.jakewharton:butterknife:8.0.1'
没有加上
apt 'com.jakewharton:butterknife-compiler:8.0.1'
所以要在Module的build.gradle 加上
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
在app 的build.gradle顶部加上
apply plugin: 'com.neenbedankt.android-apt'
dependencies加上
compile 'com.jakewharton:butterknife:8.0.1'apt 'com.jakewharton:butterknife-compiler:8.0.1'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android
相关文章推荐