Butterknife: Getting Null on @BindView

Created on 31 Jul 2017  Â·  8Comments  Â·  Source: JakeWharton/butterknife

Hi, I am getting null object reference on bind view as shown below

Gradle Dependencies:

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

Packaging Options:

exclude 'META-INF/services/javax.annotation.processing.Processor'

Proguard:

# Retain generated class which implement Unbinder.
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }
-keep public class * implements butterknife.internal.ViewBinder { public <init>(); }

# Prevent obfuscation of types which use ButterKnife annotations since the simple name
# is used to reflectively look up the generated ViewBinding.
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
-keep class **$$ViewBinder { *; }
-keep class **$ViewHolder { *; }
-keep class butterknife.**$Finder { *; }

Code Snippet for initializing Activity:

*****

@BindView(R.id.username_activity_login)
public EditText et_username;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.setDebug(true);
        ButterKnife.bind(this);
*****

Gradle version:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

By using above code and configuration @BindView doesn't work, Please help to resolve this issue.

Thanks.

Needs Info

Most helpful comment

This is not a support forum. When I get time, I'll look at your sample and
determine if it's a bug or not.

On Wed, Aug 2, 2017 at 11:37 AM Ankush Goyal notifications@github.com
wrote:

Hi @JakeWharton https://github.com/jakewharton,
Please help me to resolve this issue.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/JakeWharton/butterknife/issues/1030#issuecomment-319710276,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEdLo4v2KHfv7p8itV59GbpFLqm_Jks5sUJergaJpZM4OoX7I
.

All 8 comments

The ProGuard rules and packaging options can be deleted in their entirety.

Is there generated code in the build/ folder? Without a representative sample it's impossible to know what's going on.

@JakeWharton
Only DataBindingInfo class found in build/dataBinding

package android.databinding.layouts;

import android.databinding.BindingBuildInfo;

@BindingBuildInfo(buildId="ef51ef81-e3ba-45df-9e6b-5cf48e3a5201")
public class DataBindingInfo {}

And also found data-binding-compiler, data-binding-info, data-binding-layout-out in the intermediates

And here are the ButterKnife debug logs

08-01 08:26:24.595 3990-3990/com.track.local D/ButterKnife: Looking up binding for com.track.local.controller.activities.LoginActivity
08-01 08:26:24.608 3990-3990/com.track.local D/ButterKnife: Not found. Trying superclass com.track.local.controller.activities.BaseActivity
08-01 08:26:24.612 3990-3990/com.track.local D/ButterKnife: Not found. Trying superclass android.support.v7.app.AppCompatActivity
08-01 08:26:24.617 3990-3990/com.track.local D/ButterKnife: MISS: Reached framework class. Abandoning search.

The compiler is not running and generating the code. Without a representative sample project it's impossible to know why, but it's a build problem and not a problem with this libary.

Hi @JakeWharton ,
Here is the Sample Application that contains the issue
https://github.com/goyalzz/ButterKnifeDemo.git

And here is the invite for this repo
https://github.com/goyalzz/ButterKnifeDemo/invitations

Hi @JakeWharton,
Please help me to resolve this issue.

This is not a support forum. When I get time, I'll look at your sample and
determine if it's a bug or not.

On Wed, Aug 2, 2017 at 11:37 AM Ankush Goyal notifications@github.com
wrote:

Hi @JakeWharton https://github.com/jakewharton,
Please help me to resolve this issue.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/JakeWharton/butterknife/issues/1030#issuecomment-319710276,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEdLo4v2KHfv7p8itV59GbpFLqm_Jks5sUJergaJpZM4OoX7I
.

@goyalzz You're trying to use apt and annotationProcessor at the same time, which isn't supported. Remove the dependency on apt and change your Dagger dependency to:

annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
compile 'com.google.dagger:dagger:2.11'

Thanks @colinrtwhite, It's working fine.

Was this page helpful?
0 / 5 - 0 ratings