ButterKnife 出现 NullpointException(空指针)的解决办法

原文地址:https://www.jianshu.com/p/b0999774fd15

使用了ButterKnife8.8.1后出现空指针的问题,但也有些人说没问题。我看了这两个人的配置,基本都是按照JakeWharton大神在github上面说明进行配置的;但为什么一个是正常的,而一个却出现空指针?

buildscript {

    repositories {

        mavenCentral()

    }

    dependencies {

        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'

        ...

    }

}

apply plugin: 'com.jakewharton.butterknife'

apply plugin: 'com.android.library'

apply plugin: 'com.jakewharton.butterknife'

dependencies {

    ...   

    compile 'com.jakewharton:butterknife:8.8.1'

    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

}

经过仔细对比了一下

发现出错的一方是因为在library module里面进行如下引用

  compile 'com.jakewharton:butterknife:8.8.1'

  annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

而未出错的一方是因为在app module里面进行如下引用

  compile 'com.jakewharton:butterknife:8.8.1'

  annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

有些项目可能由几个依赖的library module和app module组成,所以由于依赖关系,

compile 'com.jakewharton:butterknife:8.8.1'

butterknife的导入必须放在library module。

那么如何解决呢?解决方法很简单,在 app module 内引用 annotationProcessor

 annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

 而在 library  module内引用 butterknife 即可解决。

compile 'com.jakewharton:butterknife:8.8.1'



作者:自由懒散的码农
链接:https://www.jianshu.com/p/b0999774fd15
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值