1. @BindView(R.id.email_sign_in_button)
2. Button emailSignInButton;
3.
4. @Override
5. protected void onCreate(Bundle savedInstanceState) {
6. super.onCreate(savedInstanceState);
7. setContentView(R.layout.activity_login);
8.
9. ButterKnife.bind(this);
10.
11. // @OnClick()点击事件失效,所以采用该方式测试
12. // @OnClick() Click event failure, so the test using this way
13. emailSignInButton.setOnClickListener(new View.OnClickListener() {
14. @Override
15. public void onClick(View view) {
16. ToastUtils.showShort(LoginActivity.this, "Can help me? thanks.");
17. }
18. });
19. }
20.
21.@OnClick(R.id.email_sign_in_button)
22.public void onClick() {
23. ToastUtils.showLong(this, "output");
24.}
But 13 line error: java.lang.NullPointerException
Module gradle:
dependencies {
// 编译ButterKnife注解框架(Compile ButterKnife annotation framework)
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
是我的配置出错了么?(Is my configuration error?)
dependencies { compile ‘com.jakewharton:butterknife:8.4.0’ annotationProcessor ‘com.jakewharton:butterknife-compiler:8.4.0’ }
我发现添加以上代码到 app‘s build.gradle 是正确的。 但是添加到library’s build.gradle 就会java.lang.NullPointerException.
@LeifDong
apply plugin: ‘com.android.library’ apply plugin: ‘com.jakewharton.butterknife’ classpath ‘com.jakewharton:butterknife-gradle-plugin:8.4.0’ 这三个是使用本地库的时候需要的 compile ‘com.jakewharton:butterknife:8.4.0’ annotationProcessor ‘com.jakewharton:butterknife-compiler:8.4.0’ 这两个是使用gradle库需要的
分开使用,别一起用
In my above everyone whos like me beacuse i am every biger and longer and handsome, look at this !!! replace the 'annotationProcessor ’ with ‘apt’. sample: dependencies { compile ‘com.jakewharton:butterknife:8.4.0’ apt ‘com.jakewharton:butterknife-compiler:8.4.0’ }
i am your brother.
@maoxiandemeng 改你主 Module 中的 build.gradle 和项目中的 build.gradle
1.在你主 Module 下 build.gradle 中的 apply plugin: ‘com.android.application’ 的下面加入
3.在你项目下的 build.gradle 中的 dependencies 里加入
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'use
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8in your root build.gradle dependencies, addapply plugin: 'android-apt'in your app.gradle, Then usecompile 'com.jakewharton:butterknife:8.4.0' apt 'com.jakewharton:butterknife-compiler:8.4.0'as the app.gradle dependencies. Get it!@ljf1172361058 我测试发现如果使用apply plugin: 'com.neenbedankt.android-apt’会造成空指针
第一阶段:下面配置可以正常工作,生成对应的xxxActivity_ViewBinding dependencies{ implementation ‘com.jakewharton:butterknife:9.0.0-SNAPSHOT’ annotationProcessor ‘com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT’ }
第二阶段:新项目添加了kotlin环境,在app.gradle中添加了下面的代码,就不能编译自动生成xxxActivity_ViewBinding了,到了指定界面就报NullPointerException
apply plugin: ‘kotlin-android’ apply plugin: ‘kotlin-kapt’ // 经过排查是这段代码产生了影响
解决办法有两种: 1、apply plugin: ‘kotlin-kapt’ 这行代码注释,(不推荐) 2、把annotationProcessor这一块改成kapt。就可以了。kapt 也能够处理Java 文件,所以不需要再保留 annotationProcessor 的依赖 dependencies{ implementation ‘com.jakewharton:butterknife:9.0.0-SNAPSHOT’ kapt ‘com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT’ }
I got this problem too,and i use it in app’s build like this: compile ‘com.jakewharton:butterknife:8.5.1’ annotationProcessor ‘com.jakewharton:butterknife-compiler:8.5.1’; My solution is delete ‘apt’ in project’s build and app’s build,I think the ‘apt’ is conflicted with ‘annotationProcessor’,only one can be retained.