gpt4 book ai didi

java - 即使资源存在于可绘制文件夹中,资源未找到异常(无法找到资源 ID)

转载 作者:行者123 更新时间:2023-12-01 10:36:24 27 4
gpt4 key购买 nike

我在 Crashlytics 中收到此崩溃报告:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.activities.TabActivity}: android.view.InflateException: Binary XML file line #27: Binary XML file line #9: Binary XML file line #9: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity + 2957(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity + 3032(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage + 1696(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage + 105(Handler.java:105)
at android.os.Looper.loop + 164(Looper.java:164)
at android.app.ActivityThread.main + 6942(ActivityThread.java:6942)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run + 327(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main + 1374(ZygoteInit.java:1374)

--
Caused by android.content.res.Resources$NotFoundException
Drawable (missing name) with resource ID #0x7f080060

Caused by android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f080060

这是我的 xml 布局文件:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true"
android:focusable="true">

<RelativeLayout
android:id="@+id/layout_header"
android:layout_width="match_parent"
android:layout_height="@dimen/px_149"
android:background="@drawable/back_nav_new_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!-- <ImageView
android:id="@+id/iv_theme_dark"
android:layout_width="@dimen/px_30"
android:layout_height="@dimen/px_30"
android:src="@color/old_background_main"
android:layout_marginBottom="@dimen/px_3"
android:layout_marginLeft="24dp"
app:layout_constraintBottom_toTopOf="@id/iv_theme_light"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="24dp" />

<ImageView
android:id="@+id/iv_theme_light"
android:layout_width="@dimen/px_30"
android:layout_height="@dimen/px_30"
app:layout_constraintBottom_toBottomOf="@id/layout_header"
android:layout_marginLeft="24dp"
android:src="@color/newColorPrimaryDark"
android:layout_marginTop="@dimen/px_3"

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iv_theme_dark"
android:layout_marginStart="24dp" />-->

<ImageView
android:id="@+id/iv_profile"
android:layout_width="@dimen/px_64"
android:layout_height="@dimen/px_64"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:contentDescription="@string/sample_description"
android:scaleType="fitXY"
android:src="@drawable/profile_avatar"
app:layout_constraintEnd_toEndOf="@id/layout_header"
app:layout_constraintTop_toTopOf="@id/layout_header" />

<TextView
android:id="@+id/nav_header_fullname"
android:layout_width="wrap_content"
android:layout_height="@dimen/px_30"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:textColor="@color/black_text"
android:textSize="@dimen/sp_15"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/iv_profile"
app:layout_constraintTop_toBottomOf="@id/iv_profile" />

<Button
android:id="@+id/btn_login"
style="@style/AppTheme.RoundedCornerCalenderButtonAllSellers"
android:layout_width="@dimen/px_65"
android:layout_height="@dimen/px_30"
android:layout_marginTop="@dimen/px_4"
android:text="@string/xml_log_and_reg_btn_login"
android:textColor="@color/black_text"
android:textSize="@dimen/sp_13"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/iv_profile"
app:layout_constraintTop_toBottomOf="@id/iv_profile" />

<TextView
android:id="@+id/nav_header_phonenumber"
android:layout_width="wrap_content"
android:layout_height="@dimen/px_30"
android:layout_marginBottom="12dp"
android:gravity="center_vertical"
android:text="@string/sample_mobile"
android:textColor="@color/black_text"
android:textSize="@dimen/sp_15"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/drawer_list"
app:layout_constraintEnd_toEndOf="@id/iv_profile" />

<Button
android:id="@+id/btn_register"
style="@style/AppTheme.RoundedCornerCalenderButtonAllSellers"
android:layout_width="@dimen/px_65"
android:layout_height="@dimen/px_30"
android:layout_marginTop="@dimen/px_4"
android:text="@string/register"
android:textColor="@color/black_text"
android:textSize="@dimen/sp_13"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/btn_login"
app:layout_constraintTop_toBottomOf="@id/btn_login" />

<ImageView
android:id="@+id/iv_launch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:contentDescription="@string/sample_description"
android:scaleX="-1"
android:src="@drawable/ic_launch"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@id/nav_header_phonenumber"
app:layout_constraintEnd_toStartOf="@id/nav_header_fullname"
app:layout_constraintTop_toBottomOf="@id/iv_profile"
app:layout_constraintVertical_bias="0.68" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/drawer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/px_8"
app:layout_constraintTop_toBottomOf="@+id/layout_header" />

</androidx.constraintlayout.widget.ConstraintLayout>

此崩溃在 4 台设备中发生了 12 次。我怎么解决这个问题?

最佳答案

当我为 28 版创建应用程序并尝试在 21 版设备上运行它时,也发生了同样的问题。我的所有 PNG 文件都在“res/drawable”中,看起来是这样。仔细一看,文件名后面有灰色的“(v24)”。实际上,除了一个之外的所有文件都在“res/drawable-v24”中。我将它们(在 Android Studio 之外)移动到“res/drawable”,一切都很好。

关于java - 即使资源存在于可绘制文件夹中,资源未找到异常(无法找到资源 ID),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58409281/

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