Butterknife避免NullPointerException之Android studio

Butterknife使用

  • 在Module下的build.gradle添加jar compile 'com.jakewharton:butterknife:8.5.1'
    activityfragment中进行绑定:ButterKnife.bind(this);
  • 使用Butterknife会出现空指针异常。具体解决方案:
    在项目的build.gradle下添加classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
    }
}

然后在app目录下的build.gradle添加

compile 'com.jakewharton:butterknife:8.5.1'
 annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

并导入apply plugin: 'com.jakewharton.butterknife'
Rebuild一下就好了

你可能感兴趣的:(Butterknife避免NullPointerException之Android studio)