Search code examples
androidimageandroid-studioandroid-drawablenine-patch

LinearLayout background not found


I know this background image exists and it's in the following drawable folders:

  • res/drawable-mdpi/
  • res/drawable-hdpi/
  • res/drawable-xhdpi/
  • res/drawable-xxhdpi/

The file is named coming_up.9.png as it's a nine patch and I know this works because I'm doing the same with a number of other images.

Layout XML

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/coming_up">

The Error

Error:(213, 37) No resource found that matches the given name (at 'background' with value '@drawable/coming_up').

Solution

  • I've been dealing with this issue for a while now and I decided today was the day to tackle it. Here's how I solved the problem:

    Steps I Took:

    1. Changed background to a different (working) image named @drawable/checkbox_checked to see what would happen - app ran fine with the new image
    2. Searched for checkbox_checked in my resource folder /res to see where it existed
    3. Found that checkbox_checked.png was only in the main /drawable folder
    4. Copied coming_up.9.png to /drawable from /drawable-mdpi - still the same error
    5. Renamed coming_up.9.png to coming_up.png - worked
    6. Renamed coming_up.png back to coming_up.9.png - still worked
    7. Removed coming_up.9.png from /drawable while leaving it in all of my other drawable folders - worked

    Seemingly this is a bug with Android Studio that was somehow resolved at step #5. Regardless this issue is solved so I hope this saves someone the time it took me to figure it out.