android - 无法使用 Butterknife 8.1.0 注入(inject) View

标签 android android-view butterknife

我想在我的项目中使用 Butterknife。如所述Here我这样设置了 Butterknife。

在项目级模块中:

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
    }
}

在模块级别

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'

}

内部 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);
}

但是当我运行我的应用程序时,我收到以下错误消息。

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>)

谁能告诉我我在这里错过了什么?

最佳答案

好的,这是个小错误。

我在 gradle 文件中使用了不同的版本。

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

现在,当我更改版本时,它可以正常工作。所以会有一些版本冲突。

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

关于android - 无法使用 Butterknife 8.1.0 注入(inject) View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38410007/

相关文章:

android - 用另一个替换标记

android - 将已解析的 Json 数据更新到 Listview

android - 缩放 Activity

java - 在 onCreateViewHolder 中获取 View 的位置

java - 一次将一个 View 添加到后台线程中的线性布局,而不是在所有操作完成后

android - 无法同步 Gradle,找不到 com.android.support :support-annotations:23. 3.0

java - 多种 Activity 中的 ButterKnife

android - 更新 Google Ads SDK 后 onAdFailedToLoad 已弃用,如何解决?

java - Android ListView 与详细信息页空对象

android - 如何使用 Butterknife 获取 fragment xml 的引用