Asim Zaidi
Asim Zaidi

Reputation: 28284

Android image can't convert to drawable

I am not able to add image. I downloaded the image and added it to res directory under drawable-mdpi. Then when I try to add the image on the view using imageView, it gives me this error

Couldn't resolve resource @drawable/ball01 
Failed to convert @drawable/ball01 into a drawable

Here is my xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame" >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:layout_gravity="center"
        android:textSize="32sp"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Enlighten Me"
        android:id="@+id/button"

        android:layout_centerVertical="true"
        android:layout_alignParentRight="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_above="@+id/textView"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ball01" />


</RelativeLayout>

What am I doing wrong here.

Upvotes: 0

Views: 4328

Answers (4)

princewill okeugo
princewill okeugo

Reputation: 1

I had this problem on android studio. if you close and open project and it continues, all you need to do is RIGHT CLICK on the particular image you put in your "res" folder (that's giving the problem) and refactor-RENAME. Remove spaces in the name of the file. that should do it.

Upvotes: 0

Treebeard
Treebeard

Reputation: 64

I had this same problem, I had this image which I named Barcode and then saved it into my drawable folder, then I decided it would be better to have it named barcode with a small b, so I renamed it. Then I checked if it would work, and I got the same errors as you, after changing the name in my xml to 'Barcode' with a big B, it worked.

solution for me: delete barcode image from drawable and add it again with the name I'm going to use for it, don't change the name while it is in drawable folder.

Upvotes: 0

iliaokun
iliaokun

Reputation: 29

image name must Digital or lowercase 。 ide only identification.

Upvotes: 1

Curtis Murphy
Curtis Murphy

Reputation: 304

The directory name should be 'drawable-mdpi'. Using a hyphen instead of an underscore.

Upvotes: 2

Related Questions