ButterKnife 8.4.0 @BindView 失败,nullpointerexception

来源:互联网 发布:科比常规赛数据统计 编辑:程序博客网 时间:2024/05/16 09:05

ButterKnife 8.4.0

@BindView 失败,空指针异常,跟踪进去,发现是XXXFragment的 XXXFragment$$ViewBinder 的类没有生成。


经过google。发现了解决方案。记录一下。


ButterKnife 8.4.0 not working


Per the readme, you need to include the butterknife-compiler in order 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.4.0'apt 'com.jakewharton:butterknife-compiler:8.0'}

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) and looking in Logcat


简单的说呢。就是之前只加了

  compile 'com.jakewharton:butterknife:8.4.0'

没有加上

  apt 'com.jakewharton:butterknife-compiler:8.4.0'
所以要在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.4.0'  apt 'com.jakewharton:butterknife-compiler:8.4.0'
1 0
原创粉丝点击