Image Source not found or ContentDescription is missing - android

<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

Related

How to fix android error 'Color value must start with #'?

I was trying to use an icon from this page in my layout as follows
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_backspace_black_24dp"
/>
but it could not be rendered because of an error
Color value '#drawable/ic_backspace_black_24dp' must start with #
I found two related issues in SO here and here which did not help resolve the issue.
There is no dash ('-') in the filename, the file-format is a 'png' and there is no res/color directory in my project.
All my colors defined in colors.xml start with a #.
So how to fix this error?
Simply rename your file name by removing the numbers and only keep lower case letters or underscores.
Problem solved: I forgot to remember that the android sources on the internet are really outdated, and almost none of the documentation works as-is!
The folder res/drawable as suggested in the android developer guide is deprecated! The folder is now named mipmap! So the simple solution is to have the following layout to fix the problem:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_backspace_black_24dp"
/>
Never trust the android developer documentation ... !
Try removing the '_" underscores and make the name shorter. Not sure why but that worked for me.
Check the file drawable/ic_backspace_black_24dp.
If you downloaded the SVG version you will able to open as a text file. Check if the android:fillColor has the #.
Anyway if you are using Android Studio those icons can be downloaded very easily using Vector Asset Studio:
Right click in drawable
new
vector assets
choose the icon you want
You have more info of this feature here.

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.

Android Imageview

I have kept some .png file in res->drawable-hdpi and now, I want to show it in imageview in android. But when I refer to that image from image view, android says:
Couldn't resolve resource #drawable/my_pic.
I am using the following code :
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_pic" />
I am using every file name in small letter
The size of my_pic is 36kb
So how can I load the picture? Is this problem for size or something else. How to fix this problem. Any help ?
If you dont save your changes, you get a
"Couldn't resolve resource #drawable/my_pic."
Control+S ... to save Changes, its all or..
When the R.java have a problem, only needs:
(Project -> Clean from the menus)

Doing "!" by everything I add the app

This is the first time I work with apps, so if you know a site where I can go ahead with that from then it will be super or like I have the brand new version of eclipse
This is the first time I have to work with apps for android. is in my path: ABSB/res/layout/activity_main.xml
into the file I am working to add and delete things but no matter what I do then there's always! by pictures or my button.
<ImageView
android:id="#+id/imageView1"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:src="#drawable/ic_launcher" />
Show img here to what i mean on my problem! CLICK HER
Don't worry about it. It's just a lint warning. It doesn't need to be followed.
If you hover your mouse over it. It will tell you that your image needs a string resource, so that it can be localized more easily. If it's not that specific message exactly, it will be a similar innocuous warning.
That's just Eclipse warning you of potential issues with your code. If you hover over the icon in the file itself (next to the line number) it will show the warning message. In this case it will be something along the lines of:
[Accessibility] Missing contentDescription attribute on image
You can probably safely ignore it in this case.
Hover your mouse over the yellow underlined word (like ImageView in the picture). It will tell you whats wrong. But it is just a warning not an error.

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

Categories

Resources