绑定视图时,butterKnife返回null(8.6.0) [英] butterKnife returns null when binding view (8.6.0)
本文介绍了绑定视图时,butterKnife返回null(8.6.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试执行此操作时:
When i'm trying to do this:
...
public class LoginActivity extends AppCompatActivity {
@BindView(R.id.login_form) View loginForm;
...
loginForm
获取 null
.我尝试遵循其他答案,但没有任何效果(例如,此操作).我也按照在butterKnife配置页面中所说的做了,并且没有用.我在做什么错了?
loginForm
is getting null
. I tried to follow other answers and nothing worked (this for example). I also did exactly what it said in the butterKnife configuration page and it didn't work. What am I doing wrong?
模块gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "name"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'uk.co.chrisjenx:calligraphy:2.3.0'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
项目gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.6.0'
推荐答案
可能忘记了这一行:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
...
}
这篇关于绑定视图时,butterKnife返回null(8.6.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文