Android Studio - Failed to convert #drawable/ into a drawable - android

I am getting this error when I am trying to use an image in Layout file:
Couldn't resolve resource #drawable
Failed to convert #drawable/image into a drawable
Here is my layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/image"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
I tried restart IDE, clean-rebuild but nothing, and I read all threads related to it ( I think ).
And yes my image name contains only [a-z0-9_.].

I had the same problem, I solved it by renaming my image into something like : my_image.

Well, I found a way to avoid this
RightClick on drawable folder then New => File insert its name (myImage)
for example Then Select Image Files.
Then in drawable folder I replaced myImage file with the real image.

Related

Failed to convert drawable into a drawable

I'm getting the error "Failed to convert #drawable/12234 into a drawable" where 12234 is my image name, that is placed inside the drawable folder.
I'm able to assign other images that are smaller, however when I try to assign this image it gives me an error.
Here is my code for my Imageview xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_alignParentTop="true"
android:src="#drawable/12234"
android:adjustViewBounds="true"
android:longClickable="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
According to documentation drawables resources must satisfy the following:
File-based resource names must contain only lowercase a-z, 0-9, or _.
And also in your case it cannot be all numbers, it has to have at least one letter.
I solved the issue by renaming the image to have a character first.
Changed image name from 12234.jpg to r12234.jpg
In Adroid Studio's Design View, try just clicking the refresh icon, the one that looks like two curved arrows facing each other.
This worked for me - I didn't need to rename anything or restart my computer.
I'm running ver 1.5.1, Marshmallow, API 23.
I have been stumbling for many hours, read almost all answers on all questions but nothing worked. Finally, I have found a solution that worked.
What i did
Showed "drawable" in explorer
Replaced ALL ı's with i's (drawable-hdpı -> drawable-hdpi, renamed
all folders) Then the folders didn't appear in android studio
Replaced only 2 i's with ı's (drawable-hdpi -> drawable-hdpı, renamed
2 folders) Afterwards, all the images started to appear and finally
i was able to add images.

Setting up a background image in Android Project

I'm building an Android App using Eclipse. I'm trying to create a simple image display when the application opens.
I've saved my intro_image.png on res\drawable-hdpi in my workspace, I've created another xml for the layout with the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/intro_image">
</LinearLayout>
An error message appears when I view the result on the Graphical Layout, saying: "Failed to convert #drawable/into_image into a drawable. Couldn't resolve resource #drawable/intro_image"
How do I solve this?
Thank you.
try to refresh or clean your project. it will work.whenever you paste an image into drawable you have to refresh that folder.

ImageView inside LinearLayout not working

I have the following layout, each time I try to view it in the Graphical Layout it gives the error message below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/my_greeting" />
</LinearLayout>
The error
The following classes could not be found:
- ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)
close that file and reopen it. if wont solve the problem just clean and rebuild the project.
It's got to do something with your image source my_greeting. Check if the source name is right and check if you've given a valid extension. Also, try cleaning the project.

Why the ImageView class is not found?

i'm having troubles with creating the first android app (Silent Toggle Mode from the pdf "Android.Application.Development.for.For.Dummies" ) with inserting an Imageview in the main.xml file, when I go to the graphical layout, the image isn't showing itself and this error appears:"The following classes could not be found:
- ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)"
this is my xml code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="#string/hello_world"
android:orientation="vertical"
tools:context=".MainActivity" >
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<ImageView
android:id="#+id/phone_icon"
android:contentDescription="#string/description"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/phone_on" />
<Button
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ToggleSilentMode" />
</LinearLayout>
thanks
This is one issue that I have also run across recently. It was sort of a misleading error to me and kept me stumped for around 30 minutes this morning. It isn't that Android cannot find the class. It is that it is having trouble importing the image source file.
Now the reason that it is having trouble finding the image is because I did not copy the source image into the directory correctly. I have chosen to drag the source file from another folder directory into the appropriate locations. In the process, it did not copy the file over properly. Or it copied it over as just a link to the other resource.
As a result Android does not know what to do with the resource and throws that odd error. In order to resolve this problem, you need to delete the old image sources and then replace them with direct full copies of their equivalents. Then you should see this error go away and the application working as expected from the xml layout code.
I faced the same problem once. To get it out, I replaced all the existing images, now it worked.
I had the same issue, when added a new ImageView in my xml with an image src.
I tried to open this image with Photoshop and get an "module format error". So the image was corrupted. The problem was solved creating a new image similar to the first one.
Hope it works :)

Background image of Activity

How can I include an image as the background and where and how to put an image in the application, I am using Eclipse and all the development tools.
Here's what I have done so far in the main_activity.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0C0C0"
tools:context=".MainActivity">
</RelativeLayout>
put your image in res/drawable directory
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_imagename"
tools:context=".MainActivity" >
</RelativeLayout>
just search and you will get it.
just put your image inside res/drawable folder and change
android:background="#C0C0C0"
to
android:background="#drawable/your_image_name" (dont give extension of image)
Put a .jpg or .png image inside the res/drawable folder and change the background attribute to this:
android:background="#drawable/image-name"
where image-name is the actual name of the image.
As you'll see, there are several drawable folders, like drawable-mdpi or drawable-hdpi. They are designed to store images for devices with different screen density. To make sure your application looks good on different devices, provide alternative images for every density. The #drawable/image-name attribute doesn't need to be changed then, the Android will pick the right drawable folder for you. Hope this helps.
You can only use .jpg and .png format images. after that,
copy your image and paste it in res Folder in your application.
if the name of your image is image.png
use this code..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/image"
tools:context=".MainActivity" >
</RelativeLayout>

Categories

Resources