Resources Not Found Exception (Unable to find resource ID) even though resources exist in drawable folder
Asked Answered
G

3

11

I'm getting this crash report in 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

This is my xml layout file:

<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>

This crash occurred 12 times in 4 devices. How can I solve this problem?

Goodwill answered 16/10, 2019 at 8:47 Comment(8)
May be issue is in your @drawable/profile_avatar or inside @drawable/ic_launch Make sure your @drawable/profile_avatar and @drawable/ic_launch images is inside drawable folder not inside drawable-v24 folderHauptmann
Can you post the relavant java code of itMainstream
@NileshRathod profile_avatar.png exists in drawable and drawable-xhdpi folders and ic_launch.xml exists in drawable folder.Goodwill
@karthikvishnukumar Crash is not related to java class because it occurred in inflating line View v = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);Goodwill
@AlirezaNoorali . There is a possibility that if you set int as text in your textview you'll get this kind of exception. Consider this check as wellMainstream
@karthikvishnukumar I just set Strings as text in textviewsGoodwill
Possible duplicate of Resource Not found exception in androidBissau
User high resolutions images and add it to xxxhdpi - draawble. No need to add any other images in remaining drawables.Opportune
T
3

The same problem occurred when I created an app for version 28 and than tried to run it on a version 21 device. I had all my PNG files in "res/drawable", so it seemed. On closer look there was "(v24)" showing up in gray behind the file names. And in reality all files but one were in "res/drawable-v24". I moved them (outside Android Studio) to "res/drawable" and all was fine.

Tenement answered 12/12, 2019 at 12:19 Comment(0)
F
0

I just had the same weird problem with vector drawable assets with stock icons. Suddenly my_image.xml stopped displaying the actual png files in the design tab. I recreated and it started working again. If the image asset has an XML file, double-click the file and check the 'design' tab (among code/split/design) to see if the project is reading your asset correctly. With a broken file, the design tab showed nothing but a black background.

Feriga answered 10/10, 2020 at 13:3 Comment(0)
E
-1

I think you need to check which folder has your drawables, moving it from drawable-v24 to drawable should help. Also, if you're working with multiple packages, ensure that you are adding the images to correct package's drawable folder. Clean and build, your error will be resolved. Hope it works, all the best.

Excerpt answered 12/12, 2019 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.