2016-09-25 67 views
1

我想綁定TextView使用Butterknife我有主要活動和佈局組成的TextView ID爲tv_app_name。我從documentation得知。黃油刀:找不到。嘗試超類android.support.v7.app.AppCompatActivity

public class MainActivity extends AppCompatActivity { 

@BindView(R.id.tv_app_name) 
TextView tvAppName; 

@BindString(R.string.app_name) 
String appName; 

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

    ButterKnife.setDebug(true); 

    tvAppName.setText(appName); 


} 
} 

我與所述tvAppName沒有被初始化並顯示nullPointerException一個問題遇到。我添加了ButterKnife.setDebug(true);正如在StackOverflow中的一些答案建議我發現在日誌中顯示ButterKnife: Not found. Trying superclass android.support.v7.app.AppCompatActivity

雖然我尋找解決這個問題。有些人說,增加的依賴butterknife-compiler,但我已經添加了像:

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    testCompile 'junit:junit:4.12' 

    //butterknife 
    compile 'com.jakewharton:butterknife:8.4.0' 
    apk 'com.jakewharton:butterknife-compiler:8.4.0' 
} 

是什麼問題bihinde:

ButterKnife:未找到。嘗試超類android.support.v7.app.AppCompatActivity 我該如何解決這個問題?

回答

3

您的依賴關係中存在拼寫錯誤。在您的build.gradle文件

線APK 'com.jakewharton:butterknife編譯:8.4.0'

應該

容易「融爲一體。 jakewharton:butterknife-compiler:8.4.0'

您還需要t o增加

類路徑 'com.neenbedankt.gradle.plugins:Android的貼切:1.8'

你的項目級的build.gradle文件 - 有關更多信息,請參見https://github.com/JakeWharton/butterknife#download

相關問題