您的位置:首页 > Web前端

【注解 butterknife】控件弄死都要空值异常

2016-11-23 14:26 169 查看
1、以前都没问题,今天导入,就空值了。

使用的butterknife的版本是8.4.0,https://github.com/JakeWharton/butterknife

2、根据github上的说明,每个地方都配置了,都是空值



3、网上解决办法。很多人说可以,我这儿就不行

// 项目 build-gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
// module build-gradle
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}


4、嗯。。。有段时间没用了。。。忘了在onCreate里面绑定activity了。。。就空值了。。。。

。。。。人家github上的说明是对的。。。。。

。。。。。。爱上自己。。。。。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aty_search);
// 这句
ButterKnife.bind( this ) ;
}


补充

5、关于APT

(0)http://blog.sina.com.cn/s/blog_4c925dca0100hsyt.html

(1)APT(Annotation Processing Tool )是官方提供的,可以在编译期解析注解,生成新的java文件。

(2)注解有两种方式,一是运行时利用反射机制,二是编译时生成代码。后者减少手动的代码输入,提高效率。

(3)现在比较出名的注解框架Dagger2, ButterKnife都是用的APT方式。

(4)红框内容要与 apply plugin 一起配合用

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息