gpt4 book ai didi

Android:butterKnife - @BindView - 抛出 NPE

转载 作者:行者123 更新时间:2023-11-29 16:49:06 25 4
gpt4 key购买 nike

安卓工作室 2.3.3。

我的布局 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ProgressBar
android:id="@+id/downloadProgressBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

在我的app/build.gradle中:

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.myproject"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
dev {
initWith(debug)

}
}

}

dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTER_KNIFE_VERSION"
compile "com.jakewharton:butterknife:$BUTTER_KNIFE_VERSION"
}

这里是 MyActivity 的 fragment :

public class MyActivityextends extends AppCompatActivity  {
@BindView(R.id.downloadProgressBar) ProgressBar downloadProgressBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pdf_viewer_activity);
ButterKnife.bind(this);
ButterKnife.setDebug(true);
// THROW NPE!!!
downloadProgressBar.setVisibility(View.GONE);
}
}

但是在开始这个 Activity 后我得到了 NPE:

NullPointerException at com.myproject.MyActivity.onCreate(MyActivity.java:63)

为什么?我想我正确地初始化了 butterKnife 库。从 Android Studio 和控制台成功构建和运行项目。

最佳答案

你正在使用 Kotlin,所以你应该这样做

apply plugin: 'com.android.application'
//apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

dependencies {
kapt 'com.github.bumptech.glide:compiler:4.2.0'
kapt "com.jakewharton:butterknife-compiler:$BUTTER_KNIFE_VERSION"
compile "com.jakewharton:butterknife:$BUTTER_KNIFE_VERSION"
}

关于Android:butterKnife - @BindView - 抛出 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46875989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com