- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
安卓工作室 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/
如何为具有绑定(bind) View 的适配器添加点击处理程序?刚刚开始。谢谢。 最佳答案 将其放入您的 binderView - 反正我为我工作。 public void bindView(View
我在使用 DeskClock 的一些代码时发现,当我尝试修改 CursorAdapter 时,每个项目都会调用 newView。 (我实际上想添加一个分隔线,看起来单独添加分隔线比将它们添加到单个 l
我已经受这个问题困扰好几个月了(但现在我正在调优)。但是,我现在迫切需要知道为什么我的适配器感觉有必要在一条记录上最多运行 4 次 bindView。 我有一个填充 GridView 的自定义光标适配
我试图在 ListView 中显示来自 Cursor 的信息,每行包含一个 ImageView 和一个 TextView。我有一个 CustomCursorAdapter 扩展 CursorAdapt
当覆盖 ArrayAdapter 时,我知道使用这样的模式是正确的: if(view != null){ ...create new view setting fields from data
实现时onLoadFinished() , 它需要 moveToFirst()运行良好,但为什么在实现 bindView() 时不需要这样做?对于 CursorAdapter ?以及何时使用它? on
对此可能有一个简单的答案,但尝试充分使用 Butterknife,将一些 findViewById 转换为 @BindViews,并注意到我无法在需要声明为 Final 的 View 上使用 Bind
我以前看过关于这个主题的主题:Android: Issue with newView and bindView in custom SimpleCursorAdapter仍然不明白我的代码有什么问题。
安卓工作室 2.3.3。 我的布局 xml 文件: 在我的app/build.gradle中: apply plugin: 'com.android.application' appl
如果可以的话,我会尽量具体 - 请耐心等待,第一次提问并且对这个平台上的编程相对较新。如果之前有人问过/回答过这个问题,我深表歉意 - 请将其链接给我。我上下搜索但发现了其他不相关的(至少对我而言)问
我目前正在编写一个应用程序,需要根据数据库中的条目在 ListView 中设置图像。 我直接在 customCursorAdapter 的 bindView() 方法中通过 switch-case 实
我正在开发一个带有 listView 的 Android 应用程序,并且正在对其进行优化。它在一个 Activity 中使用自定义游标适配器,我注意到 bindview() 为列表的每一行触发了两次。
我正在使用 Butterknife 绑定(bind) View 。当绑定(bind)多个 View 时喜欢Acting on Multiple Views In a List , @BindViews
我创建了一个扩展 CursorAdapter 的类,我在 bindView 方法上遇到问题。 @Override public void bindView(View v, Context contex
我正在学习 android,对此了解不多,但显然节省资源很重要,所以我想知道设置背景颜色的一种做法是否明显优于另一种: 对我来说,在“onCreateViewHolder”中设置 View 的背景颜色
我正在使用自定义 CursorAdapter(帖子)在 ListView 中显示数据。有些帖子没有评论(我想显示相关信息)并且数据在不同的游标中(我无法加入表格,因为我按帖子 ID 分组以防止 Lis
我制作了自定义的 SimpleCursorAdapter,这样当没有电话号码时我可以单击 ListView 中的按钮(按钮需要调用某人)我希望按钮不可见,起初我的代码正确显示所有内容但是当我向上滚动并
我试图在 CursorAdapter 中的 bindView 方法的匿名内部类中获取 FragmentActivity 引用。实际上,当在我的 ListView 中单击 ImageView 时,我试图
我正在创建一个 ListView ,它有两个 TextView 和一个自定义 View 作为选择指示器,以加载数据我正在使用 CursorAdapter 并覆盖 bindView 和 newView。
我试图在不使用 Butterknife 方法的情况下编写以下代码,主要用于学习目的。任何人都可以在没有使用的情况下帮助编写它吗? 我猜这是 TextView textName = findViewBy
我是一名优秀的程序员,十分优秀!