找不到资源异常(即使资源位于可绘制文件夹中,也找不到资源ID)

问题描述 投票:2回答:1

我在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次。我该如何解决这个问题?

java android android-layout runtimeexception inflate-exception
1个回答
0
投票

当我为版本28创建应用程序并试图在版本21设备上运行该应用程序时,发生了相同的问题。我的所有PNG文件都保存在“ res / drawable”中,因此看来。仔细观察后,文件名后的灰色部分显示了“(v24)”。实际上,除了一个文件外,所有文件都在“ res / drawable-v24”中。我将它们(在Android Studio外部)移到了“ res / drawable”,一切都很好。

© www.soinside.com 2019 - 2024. All rights reserved.