I have all my pictures saved in the drawable-xhdpi folder. I have a total of six images, it shows 4 but not the last two despite me using the same code for both in the xml file.
<ImageView
android:id="#+id/button4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/textView4"
android:onClick="food"
android:src="#drawable/foods" />
^ That one is viewable
<ImageView
android:id="#+id/button6"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:layout_alignRight="#+id/textView4"
android:onClick="parking"
android:src="#drawable/parking" />
^ This one isn't.
This is what I get when viewing through Graphical Layout
The following classes could not be found:
- ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)
Again, both images are contained within the same folder. It might be obvious, I'm relatively new to android.
Go to Project -> Clean... from the top bar in eclipse. Then a good old restart of the graphical view might help as well.
i faced same problem , if you are using image saved .icon extension it may cause this problem.
change your image type. hope this help.
Related
<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
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.
This question already has answers here:
How can I use a system provided icon in Android (e.g. expander_ic_maximized)
(3 answers)
Closed 8 years ago.
Attempt 1:
<ImageView
android:id="#+id/star_contact"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="5dp"
android:src="#android:drawable/btn_star_big_off"/>
But it is showing a white hollow star instead of yellow star.
Attempt 2:
<ImageView
android:id="#+id/star_contact"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="5dp"
android:src="#android:drawable/btn_star_big_off_pressed"
visibility="gone"/>
But I am getting this error:
resource is not public at src with value '#android:drawable/btn_star_big_off_pressed'
Is there a way to fix my 2nd attempt's error?
Is there a way to initially set android resource star image to be pressed?
I appreciate help and willing to tick a correct answer.
In general, it's better to copy drawables from Android and use them, rather than directly use the Android drawables. Take a look at the downloadables from Android SDK. Take a look at this question for how to access them as well.
It used to be the advice on the Android Design documents to always do things this way, but that advice seems to be removed. Still, if you're having problems, you can always try this.
You are looking at this drawable
android.R.drawable.btn_star_big_on
This post here has a corresponding icon along with the drawables available in android.R package. So in your case it will be
android:src="#android:drawable/btn_star_big_on"
I did a test in my device with this imageview
<ImageView
android:id="#+id/star_contact"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="5dp"
android:src="#android:drawable/btn_star_big_on"/>
It is showing yellow like this:
Here is the list of drawable that are accessible
If it's not in the list, then you have to add drawables in your project and access from there.
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.
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 :)