Unable to inject view using Butterknife 8.1.0
Asked Answered
C

2

6

I want to use Butterknife in my project . As described Here I set up Butterknife like this.

In Project level module :

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

In Module Level

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.id.myprojectid"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    useLibrary 'org.apache.http.legacy'
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile files('libs/libphonenumber-7.0.4.jar')
    compile files('libs/universal-image-loader-1.9.5.jar')
    compile files('libs/httpmime-4.1.jar')
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.google.android.gms:play-services-analytics:7.3.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.jakewharton:butterknife:8.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'

}

Inside Activity

 @BindView(R.id.et_password) EditText et_password;
    @BindView(R.id.et_fullname)  EditText etFullname;
    @BindView(R.id.et_email) EditText etEmail;
    @BindView(R.id.et_contact) EditText et_contact;
    @BindView(R.id.et_refer)  EditText et_referId;
    @BindView(R.id.cbPasswordVisible) CheckBox checkBox;


protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);
        ButterKnife.bind(this);
}

But when i run my application i get this following error message.

Error:(20, 32) error: method castView in enum Finder cannot be applied to given types;
required: View,int,String,Class<T>
found: View,int,String
reason: cannot instantiate from arguments because actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in method <T>castView(View,int,String,Class<T>)
Error:(22, 31) error: method castView in enum Finder cannot be applied to given types;
required: View,int,String,Class<T>
found: View,int,String
reason: cannot instantiate from arguments because actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in method <T>castView(View,int,String,Class<T>)

Can anybody tell me what am i missing here ?

Cramoisy answered 16/7, 2016 at 10:6 Comment(3)
Please consider cleaning your project and then rebuildDouro
Thanks for comment i did that you suggested . But i have found solution . I was using two different versions in my gradle file . pls have a look a my answer. @DouroCramoisy
I am glad you figured it out; happy codingDouro
C
10

Ok It was minor mistake .

I was using different versions in gradle files .

 compile 'com.jakewharton:butterknife:8.2.1'
 apt 'com.jakewharton:butterknife-compiler:8.0.1'

now when i changed version its working properly. So some version conflict would be there.

compile 'com.jakewharton:butterknife:8.2.1'
  apt 'com.jakewharton:butterknife-compiler:8.2.1'
Cramoisy answered 16/7, 2016 at 10:16 Comment(5)
This answer saved me after I spent a good couple of hours going round in circles. Thanks.Borszcz
I copied the compiler import from the changelog. That caused this issue. ThanksPrecipitancy
Thanks, I had done the same thing. your answer helped mePashto
An annotation processor was included in the Gradle version 2.2, so there is no reason to provide an extra one. Check my updated answer here.Influential
exactly my case (with the same versions). Thank you!Hawaiian
H
9

Just one more suggestions on this issue add in your gradle file. apply plugin: 'android-apt'

This save me as I faced similar kind of issue . Error:(29, 0) Could not find method apt() for arguments [com.jakewharton:butterknife-compiler:8.4.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Hawk answered 16/9, 2016 at 18:50 Comment(1)
Thanks for that! I would like to put one more thing. Do not forget to add classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' in your build.gradle as well.Martineau

© 2022 - 2024 — McMap. All rights reserved.