Android image cannot convert to graphic

I can not add image. I uploaded the image and added it to the res directory in drawable-mdpi. Then, when I try to add an image to 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.

0
source share
4 answers

The directory name must be "drawable-mdpi". Use hyphens instead of underscores.

+2
source

The image name must be digital or lowercase. Identification only.

+1
source

I had the same problem, I had this image that I called Barcode and then saved it in my drawable folder, then I decided that it would be better if he called the barcode small b, so I renamed it. Then I checked if this would work, and I got the same errors as you, changing the name in my xml to "Barcode" with big B, it worked.

for me: remove the barcode image from drawable and add it again with the name that I will use for it, do not change the name while it is in the folder with the ability to transfer.

0
source

I had this problem on an android studio. if you close and open the project and it continues, all you have to do is RIGHT CLICK on the specific image that you put in the "res" folder (which gives the problem) and refactor-RENAME. Remove spaces in the file name. it should do it.

0
source

Source: https://habr.com/ru/post/982846/


All Articles