gpt4 book ai didi

java - 未找到包含字段 id 的所需 View ,但 id 存在

转载 作者:行者123 更新时间:2023-12-01 19:46:47 27 4
gpt4 key购买 nike

我有一个小问题。

我正在尝试使用 ID ongoing_call_layout 进行 BindView。我有那个 id,它存在并且它是 xml 中的 ConstraintLayout 对象。运行程序时,它的行为就像 id“ongoing_call_layout”不存在一样。

我尝试清理和重建项目,并使用 findViewById 而不是 BindView,但它仍然表示该 id 不存在。

代码本身以粗体显示(AndroidStudio 知道 id 在哪里)。

下面是相关代码

这是我的OngoingCallActivity.java(错误来自哪里):

@BindView(R.id.ongoing_call_layout) ConstraintLayout mOngoingCallLayout;
.
.
.
ButterKnife.bind(this);
.
.

错误:

Unable to start activity ComponentInfo{com.chooloo.www.callmanager/com.chooloo.www.callmanager.ui.activity.OngoingCallActivity}: java.lang.IllegalStateException: Required view 'ongoing_call_layout' with ID 2131362055 for field 'mOngoingCallLayout' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.

这是我的on_going_call.xml(ID 的来源):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ongoing_call_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr"
tools:context=".ui.activity.OngoingCallActivity">

<!-- Call Timer -->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guide_status_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="24dp" />

<TextView
android:id="@+id/text_stopwatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guide_status_bar"
tools:text="00:00" />

<!-- Caller Number (Temporary) -->

<!-- Caller Pic -->

<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="129dp"
android:layout_height="135dp"
app:layout_constraintBottom_toTopOf="@+id/text_caller"
app:layout_constraintEnd_toEndOf="@+id/text_caller"
app:layout_constraintStart_toStartOf="@+id/text_caller"
app:layout_constraintTop_toBottomOf="@+id/text_stopwatch">

<ImageView
android:id="@+id/image_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tint="@color/selector_button_icon"
app:srcCompat="@drawable/ic_account_circle_black_24dp" />

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:civ_border_width="0dp" />

</FrameLayout>

<!-- Caller Name -->
<TextView
android:id="@+id/text_caller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4"
android:textColor="?attr/iconColor"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/text_status"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
tools:text="Jesus" />

<!-- Call Status -->
<TextView
android:id="@+id/text_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="?attr/colorAccent"
app:layout_constraintBottom_toTopOf="@+id/guide_eye_level"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="@+id/text_caller"
tools:text="@string/status_call_incoming" />

<!-- Hold Button -->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guide_eye_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.44" />

<ImageView
android:id="@+id/button_hold"
android:layout_width="@dimen/flat_button_size"
android:layout_height="62dp"
android:layout_marginStart="16dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="@drawable/ripple_oval"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/flat_button_padding"
android:tint="@color/selector_button_icon"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/button_add_call"
app:layout_constraintEnd_toStartOf="@+id/button_speaker"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button_mute"
app:layout_constraintTop_toTopOf="@+id/guide_eye_level"
app:layout_constraintVertical_bias="0.32999998"
app:layout_constraintVertical_chainStyle="packed"
app:srcCompat="@drawable/ic_pause_black_24dp"
tools:visibility="visible" />

<!-- Mute Button -->
<ImageView
android:id="@+id/button_mute"
android:layout_width="@dimen/flat_button_size"
android:layout_height="@dimen/flat_button_size"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="@drawable/ripple_oval"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/flat_button_padding"
android:tint="@color/selector_button_icon"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/button_hold"
app:layout_constraintEnd_toStartOf="@+id/button_hold"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/button_hold"
app:srcCompat="@drawable/ic_mic_off_black_24dp"
tools:visibility="visible" />

<!-- Speaker Button -->
<ImageView
android:id="@+id/button_speaker"
android:layout_width="@dimen/flat_button_size"
android:layout_height="@dimen/flat_button_size"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:background="@drawable/ripple_oval"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/flat_button_padding"
android:tint="@color/selector_button_icon"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/button_hold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button_hold"
app:layout_constraintTop_toTopOf="@+id/button_hold"
app:srcCompat="@drawable/ic_volume_up_black_24dp"
tools:visibility="visible" />

<!-- Keypad Button -->
<ImageView
android:id="@+id/button_keypad"
android:layout_width="@dimen/flat_button_size"
android:layout_height="@dimen/flat_button_size"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="@drawable/ripple_oval"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/flat_button_padding"
android:tint="@color/selector_button_icon"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/button_add_call"
app:layout_constraintEnd_toStartOf="@+id/button_add_call"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/button_add_call"
app:srcCompat="@drawable/ic_dialpad_black_24dp"
tools:visibility="visible" />

<!-- Add Call Button -->
<ImageView
android:id="@+id/button_add_call"
android:layout_width="65dp"
android:layout_height="67dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:background="@drawable/ripple_oval"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/flat_button_padding"
android:tint="@color/selector_button_icon"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button_keypad"
app:layout_constraintTop_toBottomOf="@+id/button_hold"
app:srcCompat="@drawable/ic_add_black_24dp"
tools:visibility="visible" />

<!-- Answer Button -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/answer_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginBottom="32dp"
android:scaleType="center"
android:src="@drawable/ic_call_black_24dp"
android:tint="@color/green_phone"
app:backgroundTint="@color/white"
app:fabCustomSize="72dp"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:maxImageSize="36dp" />

<!-- Reject Button -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/reject_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:scaleType="center"
android:src="@drawable/ic_call_end_black_24dp"
android:tint="@color/red_phone"
app:backgroundTint="@color/white"
app:fabCustomSize="72dp"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:maxImageSize="36dp" />

<!-- Guidelines -->

</androidx.constraintlayout.widget.ConstraintLayout>

我无法声明 mOngoingCallLayout Nullable 因为它是必要的。顺便说一句,这个错误是在我从服务器合并一些代码后突然开始发生的,但与此相关的所有代码仍然是相同的。谢谢您的帮助

最佳答案

您可以尝试几种方法

  1. 重建项目
  2. 清洁项目
  3. 使缓存无效/重新启动

您还可以尝试 ButterKnife Plugin = 设置 -> 插件 -> Android ButterKnife Zelezny;

要访问插件菜单,请将键盘光标放在 setContentView(R.layout.your_activity) 中的 Activity 名称上,然后按 ALT + INSERT 它将是最后一个或第二个最后一个选项生成 ButterKnife 注入(inject)

希望这会有所帮助

关于java - 未找到包含字段 id 的所需 View ,但 id 存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59117878/

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