Butterknife: Suddenly throuwing NullPointerException

Created on 7 Feb 2017  Â·  4Comments  Â·  Source: JakeWharton/butterknife

Butterknife suddenly throwing NullPointerException. It was working fine previously.

build.gradle (Module:App)

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:support-v4:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile "com.android.support:support-vector-drawable:${supportLibVersion}"

    compile "com.google.android.gms:play-services-maps:${playServiceVersion}"
    compile "com.google.android.gms:play-services-location:${playServiceVersion}"
    compile "com.google.android.gms:play-services-places:${playServiceVersion}"
    compile "com.google.android.gms:play-services-auth:${playServiceVersion}"

    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    testCompile 'junit:junit:4.12'

    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'

    compile 'com.github.bumptech.glide:glide:3.7.0'

    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.facebook.stetho:stetho:1.4.2'
    compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'

    provided 'com.google.dagger:dagger-compiler:2.2'
    compile 'com.google.dagger:dagger:2.2'
    provided 'org.glassfish:javax.annotation:10.0-b28'

    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'

    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.google.gms.google-services'

Part of the activity class-
```
@BindView(R.id.btn_login)
TextView btnLogin;

@BindView(R.id.btn_register)
TextView btnRegister;

@BindView(R.id.btn_business)
TextView btnBusiness;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_entry);
    ButterKnife.bind(this);
    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(EntryPointActivity.this, LoginActivity.class);
            startActivity(intent);
        }
    });
**Proguard rules added-**

Retain generated class which implement ViewBinder.

-keep public class * implements butterknife.internal.ViewBinder { public (); }

Prevent obfuscation of types which use ButterKnife annotations since the simple name

is used to reflectively look up the generated ViewBinder.

-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* ; }
-keepclasseswithmembernames class * { @butterknife.* ; }
```
Any clue?

Needs Info

Most helpful comment

Yes that plugin is no longer needed. You're already using annotationProcessor for the 'butterknife-compiler' artifact which is built-in to the Android Gradle plugin.

All 4 comments

What's the stacktrace?

Hi Jack, thanks a lot for the quick response. I am unable to reproduce it. It is working fine after removing the following lines from gradle file-
build.gradle (Project)

...
dependencies {
...
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
...
}

build.gradle (app)

...
apply plugin: 'com.neenbedankt.android-apt'
...
dependencies {
...
provided 'org.glassfish:javax.annotation:10.0-b28'
...
}

Yes that plugin is no longer needed. You're already using annotationProcessor for the 'butterknife-compiler' artifact which is built-in to the Android Gradle plugin.

I am getting the above error. If I put apt "com.jakewharton:butterknife-compiler:$rootConfiguration.butterknifeVersion" then error is resolved. Can you please suggest

Was this page helpful?
0 / 5 - 0 ratings