2016-07-16 58 views
6

我想在我的項目中使用Butterknife。如上所述Here我這樣設置了Butterknife。無法使用Butterknife注入視圖8.1.0

在項目級別模塊:

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' 

} 

內部活動

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

有誰能告訴我我在這裏失蹤了什麼?

+0

請考慮清理你的項目,然後重建 – Eenvincible

+1

感謝評論我做了你的建議。但我找到了解決辦法。我在我的gradle文件中使用了兩個不同的版本。請看看我的答案。 @Eenvincible –

+0

我很高興你明白了;快樂編碼 – Eenvincible

回答

10

好吧這是一個小錯誤。

我在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' 
+0

這個答案在我花了好幾個小時圍成一圈之後就救了我。謝謝。 – jSherz

+0

我從變更日誌中複製了編譯器導入。這導致了這個問題。謝謝 – joao2fast4u

+0

謝謝,我做了同樣的事情。你的回答對我有幫助 – xrnd

9

在這個問題上 只需再添加建議在你的文件的gradle。 應用插件:「Android的易」

這救了我,因爲我遇到了類似的問題的種類。 錯誤:(29,0)無法找到類型爲org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的對象上的參數[com.jakewharton:butterknife-compiler:8.4.0]的方法apt()。

+2

謝謝!我想再提一點。不要忘記在build.gradle中添加classpath'com.neenbedankt.gradle.plugins:android-apt:1.8'。 –