EzDev.org

butterknife

butterknife - Bind Android views and callbacks to fields and methods. Butter Knife field and method binding for android views.


Using Butterknife to inject an array of views

Currently I have this array of views:

ImageView activityImageViews[] = {
    (ImageView) rootView.findViewById(R.id.img_activity_1),
    (ImageView) rootView.findViewById(R.id.img_activity_2),
    (ImageView) rootView.findViewById(R.id.img_activity_3),
    (ImageView) rootView.findViewById(R.id.img_activity_4)
};

Is there a way I could use Butterknife to inject all those views? I need to keep them in an array (or in a way so I can iterate over them).


Source: (StackOverflow)

Difference between Dagger and ButterKnife Android

Can anyone point out the difference between Dagger and Butterknife? I know that Butterknife is a view injection library and dagger is a dependency injection library. But the documentation online seems a bit overhead for me. According to Butterknife documentation you can do non-activity injections as well, which is what dagger does? Or did I misunderstand something?

http://square.github.io/dagger/

http://jakewharton.github.io/butterknife/


Source: (StackOverflow)

Dagger and Butter Knife vs. Android Annotations

I am evaluating Dependency Injection (DI) frameworks for an Android app. The top contenders are: Dagger (with Butter Knife) and Android Annotations. I understand that Dagger and ButterKnife are from the same source- square and they complement each other. Here're are the key matrices that I am looking for:

  1. Ease of use (our build is based on Gradle and we use Android Studio IDE)
  2. Testing support (we use Robotium for functional testing and RoboLectric for unit testing)
  3. Performance (DI frameworks use reflection, which one is faster?)

Source: (StackOverflow)

ButterKnife 8.0.1 not working

I am using butterknife 8.0.1, but a nullpointerexception is appearing.

This line is on my build.grade file: compile 'com.jakewharton:butterknife:8.0.1'

this is my Main Class: (I wrote the includes properly)

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {

    @BindView(R.id.MainScreenTextView) TextView mainText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this);

        **mainText.setText("Butter knife is working fine");**
    }

and this is MainActivity.xml:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical">

    <TextView
        android:id="@+id/MainScreenTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="This is the Main Screen"
        android:textColor="#000000"
        android:background="#666666"
        android:padding="5dp"
        android:textSize="20dp"/>
</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />


Source: (StackOverflow)

Remove "Method is never used" warning for OnClick annotation in Android Studio

Sorry if this question has been asked before. I am using the Butterknife 5.0 with the latest version of Android Studio(0.5.7). How can I remove the "Method is never used" warning for methods that use the 'OnClick' Annotation of ButterKnife.I noticed that Eclipse doesnt give this warning for the 'OnClick' methods. Thanks in advance


Source: (StackOverflow)

AndroidStudio disable "Expected resource of type string"

I've just tried to generate signed apk for one of my projects (I already did this before), but (maybe since updating Android Studio) I'm getting

Error:Error: Expected resource of type string [ResourceType]

This is because I'm using Butterknife's @BindString, that is generated into something like that

target.settings = res.getString(2131230792);

How can I make studio not detect this as error? I've tried searching in settings, but without success.


Source: (StackOverflow)

Gradle DSL method not found: 'apt()'

I am trying to add the latest version of butterknife and I get this error from gradle:

Error:(31, 0) Gradle DSL method not found: 'apt()' Possible causes:

  • The project 'MyProject' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • Where my gradle mobile build.gradle is:

    plugins {
        id "net.ltgt.apt" version "0.6"
    }
    
    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
    
        defaultConfig {
            applicationId "com.mynamspace.myproject"
            minSdkVersion 19
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        wearApp project(':wear')
        testCompile 'junit:junit:4.12'
        compile 'com.jakewharton:butterknife:8.0.0'
        apt 'com.jakewharton:butterknife-compiler:8.0.0'
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile 'com.google.android.gms:play-services:8.4.0'
        compile 'com.android.support:design:23.3.0'
        compile 'com.android.support:support-v4:23.3.0'
        compile 'com.android.support:recyclerview-v7:23.3.0'
    }
    

    What's wrong with the gradle-apt-plugin?


    Source: (StackOverflow)

    Duplicate files while including butterknife with gradle

    I have a basic Android app that I created with Android Studio, and I'm having problems adding butterknife to my build. I get this error:

    Error:: duplicate files during packaging of APK C:\apps\orion\app\build\apk\app-debug-unaligned.apk
    Error:Execution failed for task ':app:packageDebug'.
    > Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
        File 1: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
        File 2: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
    

    My dependencies look like this:

    dependencies {
    
        compile 'com.android.support:support-v4:+'
        compile 'com.squareup.dagger:dagger-compiler:1.2.1'
        compile 'com.squareup.dagger:dagger:1.2.1'
        compile 'com.jakewharton:butterknife:4.0.1'
        compile 'com.google.android.gms:play-services:4.0.30'
        compile 'com.android.support:appcompat-v7:+'
        compile project(':lib')
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
    

    Source: (StackOverflow)

    Butterknife View injection

    I stumbled across a very interesting Dependency Injection library called ButterKnife. Using ButterKnife it's easily possible to inject Views into activities or fragments.

    class ExampleActivity extends Activity {
      @InjectView(R.id.title) TextView title;
      @InjectView(R.id.subtitle) TextView subtitle;
      @InjectView(R.id.footer) TextView footer;
    
      @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_activity);
        ButterKnife.inject(this);
        // TODO Use "injected" views...
      }
    }
    

    However if using Dependency Injection those Views must be public so that Butterknife can inject it (using private fields results in an exception fields must not be private or static).

    In my past project I always made all the member fields (including the views) private as I thought this is best practice (information hiding etc.) Now I am wondering if there is a reason why one should not make all the views public? In this case I cannot use ButterKnife but I want to use it because it simplifies the code a lot.


    Source: (StackOverflow)

    Using Butter Knife in Custom BaseAdapter SubClass Results in "Unable to inject views" error

    I'm attempting to use Butter Knife to simplify creation of a custom BaseAdapter class. I'm following the example here: http://jakewharton.github.io/butterknife/ under the "Another use is simplifying the view holder pattern inside of a list adapter." section. Unfortunately, I am getting an "Unable to inject views" error each time the ViewHolder is created for each item in the list.

    Here is my code:

    public class ButterknifeCustomBaseAdapter extends BaseAdapter{
    @Override
    public int getCount() {
        return arrayListNames.size();
    }
    
    @Override
    public Name getItem(int iPosition) {
        return arrayListNames.get(iPosition);
    }
    
    @Override
    public long getItemId(int iID) {
        return 0;
    }
    
    LayoutInflater inflater;
    ArrayList<Name> arrayListNames = new ArrayList<Name>();
    static Context context;
    Activity activity;
    
    public ButterknifeCustomBaseAdapter(Context context, ArrayList<Name> names, Activity activity) {
        arrayListNames = names;
        this.context = context;
        inflater = LayoutInflater.from(this.context);
    }
    
    
    
    static class ViewHolder implements View.OnClickListener {
        @InjectView(R.id.textViewFullName) TextView textViewFullName;
        @InjectView(R.id.imageButtonDeleteName) TextView imageButtonDeleteName;
        @OnClick(R.id.imageButtonDeleteName)
        public void onClick(View view) {
            ((NameActivity)context).DeleteUser((Name)view.getTag());
        }
    
        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
    
    @Override public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
    
        if (convertView != null) {
            viewHolder = (ViewHolder) convertView.getTag();
        } else {
            convertView = inflater.inflate(R.layout.item_name, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }
    
        viewHolder.textViewFullName.setText(((Name)getItem(position)).GetFullName());
        L.l("ArrayAdapterName", ((Name)getItem(position)).GetID() + " inserted in list | position = " + position);
        viewHolder.imageButtonDeleteName.setTag((Name)getItem(position));
        return convertView;
    }
    

    }

    The error happens at the "ButterKnife.Inject(this, view);" line. It also happens each time the view holder is created for each item I am putting in the list. Does anybody know how to make this work the way it should?

    In reply to Jake Wharton's comment First, let me say thank you for developing this tool. It has made android development much more enjoyable than it was when I first started.

    Here is the complete stacktrace:

    05-04 07:29:01.991    2424-2424/com.murach.databasehomework E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to inject views for com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder@52700878
                at butterknife.ButterKnife.inject(ButterKnife.java:221)
                at butterknife.ButterKnife.inject(ButterKnife.java:184)
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder.<init>(ButterknifeCustomBaseAdapter.java:59)
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter.getView(ButterknifeCustomBaseAdapter.java:70)
                at android.widget.AbsListView.obtainView(AbsListView.java:2177)
                at android.widget.ListView.makeAndAddView(ListView.java:1840)
                at android.widget.ListView.fillDown(ListView.java:675)
                at android.widget.ListView.fillFromTop(ListView.java:736)
                at android.widget.ListView.layoutChildren(ListView.java:1655)
                at android.widget.AbsListView.onLayout(AbsListView.java:2012)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
                at android.view.Choreographer.doCallbacks(Choreographer.java:562)
                at android.view.Choreographer.doFrame(Choreographer.java:532)
                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
                at android.os.Handler.handleCallback(Handler.java:730)
                at android.os.Handler.dispatchMessage(Handler.java:92)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.reflect.InvocationTargetException
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at butterknife.ButterKnife.inject(ButterKnife.java:216)
                at butterknife.ButterKnife.inject(ButterKnife.java:184)
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder.<init>(ButterknifeCustomBaseAdapter.java:59)
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter.getView(ButterknifeCustomBaseAdapter.java:70)
                at android.widget.AbsListView.obtainView(AbsListView.java:2177)
                at android.widget.ListView.makeAndAddView(ListView.java:1840)
                at android.widget.ListView.fillDown(ListView.java:675)
                at android.widget.ListView.fillFromTop(ListView.java:736)
                at android.widget.ListView.layoutChildren(ListView.java:1655)
                at android.widget.AbsListView.onLayout(AbsListView.java:2012)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
                at android.view.Choreographer.doCallbacks(Choreographer.java:562)
                at android.view.Choreographer.doFrame(Choreographer.java:532)
                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
                at android.os.Handler.handleCallback(Handler.java:730)
                at android.os.Handler.dispatchMessage(Handler.java:92)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.TextView
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder$$ViewInjector.inject(ButterknifeCustomBaseAdapter$ViewHolder$$ViewInjector.java:13)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at butterknife.ButterKnife.inject(ButterKnife.java:216)
                at butterknife.ButterKnife.inject(ButterKnife.java:184)
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder.<init>(ButterknifeCustomBaseAdapter.java:59)
                at com.murach.databasehomework.ButterknifeCustomBaseAdapter.getView(ButterknifeCustomBaseAdapter.java:70)
                at android.widget.AbsListView.obtainView(AbsListView.java:2177)
                at android.widget.ListView.makeAndAddView(ListView.java:1840)
                at android.widget.ListView.fillDown(ListView.java:675)
                at android.widget.ListView.fillFromTop(ListView.java:736)
                at android.widget.ListView.layoutChildren(ListView.java:1655)
                at android.widget.AbsListView.onLayout(AbsListView.java:2012)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                at android.view.View.layout(View.java:14289)
                at android.view.ViewGroup.layout(ViewGroup.java:4562)
                at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
                at android.view.Choreographer.doCallbacks(Choreographer.java:562)
                at android.view.Choreographer.doFrame(Choreographer.java:532)
                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
                at android.os.Handler.handleCallback(Handler.java:730)
                at android.os.Handler.dispatchMessage(Handler.java:92)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                at dalvik.system.NativeStart.main(Native Method)
    

    Source: (StackOverflow)

    @OnClick array with optional ids (ButterKnife)

    I have an activity that inflates a view when a web request finished. Some of the widgets of this view have to be attached to one onClick method, so I have:

    @OnClick({R.id.bt1, R.id.bt2, R.id.inflated_bt1, R.id.inflated_bt2})
    public void onClick(View view) {
        // ...
    }
    

    As R.id.inflated_bt1 and R.id.inflated_bt2 don't exist when the app is created, it throws an exception suggesting to set an @Optional annotation.

    Required view 'inflated_bt1' with ID XXXXXXXX for method 'onClick' was not found. If this view is optional add '@Optional' annotation.

    Is there a way to set some of the views with the @Optional annotation and inject them when the view is inflated? Or, is there another way to do it?

    Thank you


    Source: (StackOverflow)

    Where should I unbind ButterKnife 8.x.x in a ViewHolder?

    I have a RecycleView.ViewHolder class which use ButterKnife annotations.

    Should my code unbind() in this ViewHolder class too?

    public class AView extends RecyclerView.ViewHolder
    {
        @BindView(R.id.a_text_view) TextView aText;
    
        public AView(final View view)
        {
            super(view);
            ButterKnife.bind(this, view); // It returns an Unbinder, but where should I call its unbind()?
        }
    }
    

    The docs (http://jakewharton.github.io/butterknife/) does not talk about this issue.


    Source: (StackOverflow)

    java.lang.VerifyError: Verifier rejected class on Lollipop when using release APK

    I get this error when I install my release APK on a 5.x device. The error does not occur when I push the same code from Android Studio, or if I run it on a 4.x device.

    java.lang.VerifyError: Verifier rejected class com.myapp.android.ui.activity.MainActivity$$ViewInjector due to bad method void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity) (declaration of 'com.myapp.android.ui.activity.MainActivity$$ViewInjector' appears in /data/app/com.myapp.android-2/base.apk)
           at java.lang.Class.classForName(Class.java)
           at java.lang.Class.forName(Class.java:308)
           at java.lang.Class.forName(Class.java:272)
           at butterknife.ButterKnife.findInjectorForClass(ButterKnife.java:298)
           at butterknife.ButterKnife.inject(ButterKnife.java:271)
           at butterknife.ButterKnife.inject(ButterKnife.java:184)
           at com.myapp.android.ui.activity.MyDrawerActivity.onCreate(MyDrawerActivity.java:31)
    

    I inject my Toolbar and a custom NavigationDrawer in the class.

    @InjectView(R.id.toolbar) Toolbar mToolbar;
    @InjectView(R.id.nav_drawer) MyNavigationDrawer mNavigationDrawer;
    

    Line 31:

    ButterKnife.inject(this);
    

    Is there something that would be different with the Butterknife codegen when using gradle assembleRelease? I am not using ProGuard at all.

    Here are my other Android build settings:

    # Android SDK settings
    ANDROID_BUILD_MIN_SDK_VERSION=14
    ANDROID_BUILD_TARGET_SDK_VERSION=21
    ANDROID_BUILD_SDK_VERSION=21
    ANDROID_BUILD_TOOLS_VERSION=21.1.2
    

    Logcat

    I/art     (21354): Verification error in void com.myapp.android.ui.activity.MainActivity$$ViewInjector.inject(butterknife.ButterKnife$Finder, com.myapp.android.ui.activity.MainActivity, java.lang.Object)
    I/art     (21354): void com.myapp.android.ui.activity.MainActivity$$ViewInjector.inject(butterknife.ButterKnife$Finder, com.myapp.android.ui.activity.MainActivity, java.lang.Object) failed to verify: register v4 has type Reference: com.myapp.android.ui.activity.MainActivity but expected Reference: com.myapp.android.ui.activity.LoggedInNavActivitya.lang.Object): [0x0]
    I/art     (21354): Verification error in void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity)
    I/art     (21354): void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity) failed to verify: register v1 has type Reference: com.myapp.android.ui.activity.MainActivity but expected Reference: com.myapp.android.ui.activity.LoggedInNavActivity
    E/art     (21354): Verification failed on class com.myapp.android.ui.activity.MainActivity$$ViewInjector in /data/app/com.myapp.android-1/base.apk because: Verifier rejected class com.myapp.android.ui.activity.MainActivity$$ViewInjector due to bad method void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity)
    

    Source: (StackOverflow)

    RecyclerView.ViewHolder unable to bind view with ButterKnife

    I'm using ButterKnife to bind my views on my ViewHolder. My code is below:

    public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    
        private List<DataObject> data;
    
        public MyAdapter(List<DataObject> data) {
            this.data = data;
        }
    
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_layout, parent, false);
            return new ViewHolder(view);
        }
    
        public static class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.row_header_view) View rowHeaderView;
            @BindView(R.id.row_header_view_text) TextView headerTextView;
    
            @BindView(R.id.row_data_view) View rowDataView;
            @BindView(R.id.row_data_view_text) TextView rowDataTextView;
            @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView;
    
            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }
        }
    }
    

    For some reason in my ViewHolder all of the BindView's do nothing. They are all null. I can confirm with certainty they are in my layout. What is wrong with my above code? I have used it as per the documentation listed here:

    http://jakewharton.github.io/butterknife/#reset

    Is there anything else required? I'm using ButterKnife version:

    compile 'com.jakewharton:butterknife:8.2.1'
    

    If I add the below line:

    rowHeaderView = view.findViewById(R.id.row_header_view);
    

    It's able to get the view properly. But how does this make sense? Isn't ButterKnife usable where findViewById is usable?


    Source: (StackOverflow)

    ButterKnife not working with Jack?

    I just started a very simple project and tried to use both ButterKnife and Jack compiler, but it seems they do not cope with each other well.

    Gradle plugin version: 2.2.0-alpha5

    in my module build.gradle I added:

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

    And the error message is:

    Error:Execution failed for task ':app:transformJackWithJackForDebug'.
    java.lang.AssertionError: java.lang.IllegalArgumentException
    

    Did I miss something or it's just they are not compatible?


    Source: (StackOverflow)