Failed to convert drawable into a drawable - android

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.

Related

Image Source not found or ContentDescription is missing

<ImageButton
android:layout_width="fill_parent"
android:layout_height="200dp"
android:id="#+id/imageButton"
android:scaleType="fitCenter"
android:clickable="true"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:src="#drawable/wallhaven_263366"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="65dp"
android:contentDescription="#string/imagebutton" />
this is my code.. and I tried almost every thing I found here...
I've added the image in src but its not showing in either preview or avd. some times it give error of not found src as given
or content description missing.. if I provide a content description and res value then it says could not resolve resource #string/.
any sort of help is welcomed.
Missing content description is not an error.
If you sure the file is in the Drawablr folders try to reneame it and remove the digits. SOmetimes it cause problems when using digits in file name.
Try hitting Ctrl + F9 if you are operating over windows, this will build the project. I have faced similar errors while starting up the studio and after building the project it solves them. And even try removing the extra digits from image name.
Solution :Just edited the image format to png through paint .. earlier I did by renaming it in directory.
//other problem
but still idk why none of the button or image is visible in avd yet I can add remove or edit them in preview mode.
P.S.
they are also not visible in preview just editable

ImageView of PNG doesn't appear (maybe it's too big)

Inside my AlertDialog I've an ImageView, when I choose to show the android:src="#drawable/logo_small" (a png around 64x64px in every folders /hdpi /ldpi ect..) all works fine. Instead when I show android:src="#drawable/logo_big" (it's just ONE png of 1417x1417pixel and 593KB in the drawable root folder) the image doesn't appear.
The layout:
<?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:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="#+id/imageLogoBig"
android:layout_width="30dp"
android:layout_height="30dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/logo_big" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:src="#drawable/gplay_logo" />
</LinearLayout>
The imageLogoBig doesn't show in the upper example and in the lower example:
<ImageView
android:id="#+id/imageLogoBig"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/logo_big" />
I just discovered while I was writing the question that if I delete from drawable root directory the image logo_big and if I copy it in drawable-hdpi, drawable-ldpi, drawable-mdpi and drawable-xhdpi, all works fine. And this is strange because the other image: imageView1, is only in the drawable folder (but is 172x60px) and is showed correctly.
Why is this happening? Any suggest? (For example put logo_big only in drawable-xhdpi...)
I solved moving logo_big png image only to the directory drawable-xhdpi, don't know really why, but it works now.
This can be for a number of reasons, one is the name of the file not being compliant, that's clearly not your case but I'm pretty sure it's of many others like me that would reach this question when looking for an answer.
In a nutshell, underscores '_' are permitted but hyphens '-' are not, maybe because these are used to add resource qualifiers to file names (or at least directories).
This is something easy to remember, but even easier to forget. So, to put an example, this file didn't work:
poa-sample.png
And the solution was to rename it to:
poa_sample.png
I leave this here JFTR, because as stupid as this is, it a made me waste a lot of time and try everything else before. You'd expect Android Studio to give an error at build time, as it would do with an invalid variable identifier for example, but as of today it won't give you even a proper warning.
try renaming your image file to "logobig", without an underscore and see if that works. Even though file-based resource names allow underscores, i've had trouble occasionally

R doesn't generate button

I've just finished to do the layout I want, and even although I saved everything, when I try to find by id the button, the button I'm looking for is missing.. Both the button's I have.. I've checked in the R class, under the ID, and it seems it doesn't sees' the buttons. Doesn't generate them? I dunno.. Any way, it happens every time I use relative layout!! Is there any connection? It works with TableLayout and with linear layout.. Only with relative layout it make's problems.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/Background" >
<TextView
android:id="#+id/corpTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/corpTag"
android:textColor="#color/White" />
<Button
android:id="#+id/addBusinessButton"
style="#android:style/ButtonBar"
android:layout_width="200dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="208dp"
android:text="#string/addYourBusiness" />
<Button
android:id="#+id/searchBusinessButton"
style="#android:style/ButtonBar"
android:layout_width="200dp"
android:layout_height="25dp"
android:layout_alignBottom="#+id/addBusinessButton"
android:layout_alignLeft="#+id/addBusinessButton"
android:layout_marginBottom="36dp"
android:text="#string/searchBusiness" />
I found this happening to me with a broken layout. No need to be worry. I am trying my best to giving you the solution
Solution
Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.
If you somehow hit something and created import android.R in your activity, remove it.
Run Project -> Clean. This will delete and regenerate R and BuildConfig.
Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .
Wait a few seconds for the errors to disappear.
This problem isn't related to relative layout, but is actually set on the background because Android drwable is case-sensitive and now allows you any capital letters for image or layout. Rename your image name or drwable name to "background" instead of Background."
Here is the problem with set background name:
android:background="#drawable/Background"
It might be the Android Style ButtonBar. It isn't available for every API level. So if you have a low minSDK, it's not going to build and Eclipse/IntelliJ should give you an error message in its error pane.
The rule given by Google, is that you should always define your own resources. If you want to use a resource that is in the Android name space, that's fine, but you should copy it first and package it with your apk, because that's the only way you can be assured that it will always be bundled with your application.
And yes, I realize many people and many tutorials on the web don't do it that way, but that's because most people are lazy.

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

Drawable not showing up

I have a fairly simple xml file that has an image button in it. The image shows up fine on the Graphical Layout xml designer, shows up fine when I run a development build, but as soon as I create the signed apk file and run it, the image no longer shows up. It's just an empty button. I can't think of a reason why, any ideas? The xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/navigation_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/navigation_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge" />
<SeekBar
android:id="#+id/navigation_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:padding="5dp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
<ImageButton
android:id="#+id/part_select_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/chapter_select" />
<Button
android:id="#+id/navigation_ok_button"
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/ok" />
<Button
android:id="#+id/navigation_cancel_button"
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/cancel" />
</LinearLayout>
</LinearLayout>
The image #drawable/chapter_select is a fairly small (41*41) png file that is in the res/drawable folder.
Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't show up. Added a dummy image called aaaa.png to the drawable folder and problem was solved. Found the answer here: ImageButton does not display a particular drawable
One of the reason is:
If you are using Vector file as a drawableLeft or drawableRight (or drawableStart or drawableEnd) in layout.xml, then you have to use androidx.appcompat.widget.AppCompatButton (formerly android.support.v7.widget.AppCompatButton) instead of Button.
Simple View like Button or Textview doesn't support Vector file as a drawableLeft or drawableRight (or drawableStart or drawableEnd) in my case.
Had the same issue and resolved it by removing all special characters. In my case it was dashes '-' in the filename:
background-720.png => background.png.
try to put the image in drawable-hdpi and drawable-mdpi folder
depends on what device you run you app , the image is searched in these folders...
But puting in drawable means that the image should be available everywhere, but somethimes (depends on your manifest settings) this could not be true, I mean you can turn of the compatibility mode.
also you can try dinamically at run time to set the image to the view
iv.setImageResource(R.drawable.somethig);
My situation was weird.Everything was correct until integrating FireBase Crash report to my Application.
I just added compile 'com.google.firebase:firebase-crash:11.0.1' & DrawableLeft vanished .When i went through the xml , noticed a warning (In lined below).
So added android:drawableStart & issue gone.
Still I am wondering about the relation of FireBase Crash reporting to the same.
Using left/right instead of start/end attributes Using Gravity#LEFT
and Gravity#RIGHT can lead to problems when a layout is rendered in
locales where text flows from right to left. Use Gravity#START and
Gravity#END instead.
Similarly, in XML gravity and layout_gravity attributes, use start
rather than left. For XML attributes such as paddingLeft and
layout_marginLeft, use paddingStart and layout_marginStart.
NOTE: If your minSdkVersion is less than 17, you should add both the
older left/right attributes as well as the new start/right attributes.
On older platforms, where RTL is not supported and the start/right
attributes are unknown and therefore ignored, you need the older
left/right attributes.
There is a separate lint check which catches that type of error.
(Note: For Gravity#LEFT and Gravity#START, you can use these constants
even when targeting older platforms, because the start bitmask is a
superset of the left bitmask. Therefore, you can use gravity="start"
rather than gravity="left|start".)
Check your image size. If you're using an unnecessarily large asset when actually deployed it might just not show despite looking correct in the designer.
Well ! in my case setting MinifyEnabled false and shrinkResources false is working fine now.
i was getting image from drawable. it was working pretty nice in debug version but after release version of apk it was showing sometime blank ImageView.
minifyEnabled false
shrinkResources true
**
See the Screenshots
**
Hope this may help anyone.
I had a similar problem where a drawable png was not showing up in Android Studio. Deleted the file and added it again in the drawable folder and it Worked for me.

Categories

Resources