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)
Related
This is my code. I don't know how to post this image.
I tried to add source file for my ImageView. But it doesn't work. I tried to copy the path folder and it is still not work.
Solution - first problem
The resource name must start with a letter (not number).
Solution - second problem
Use just:
#drawable/039_cloud
instead
#drawable/039_cloud/039_cloud
so:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/039_cloud" />
Android Studio
Android Studio is grouping same images, but for different DPIs.
When you choose Android view, you will have:
But when you will choose Project you will see "real" project structure:
Copy the image resource and paste it directly inside the drawable folder. Rename the image such that no number is included (e.g. image_thirty_nine.png). Then try this
<ImageView
android:id="#+id/image_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_thirty_nine" />
If you are till getting the same error after trying the above step, then try adding the image resource programmably
//ensure you assignn an id to your image
ImageView imageView = findViewById(R.id.image_id);
imageView.setImageResource(R.drawable.image_thirty_nine);
then run your code to see if it works
<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 am trying to bind an image file to an Android ImageView that is within an MvxListView. The images are just not appearing when the View is shown.
I have included the MvvmCross.HotTuna.Plugin.File package.
ListVideo.axml (snippet)
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_blue_bright"
local:MvxBind="ImageUrl Thumbnail" />
The typical value for Thumbnail is
VideoData/2015-07-24-09-26-16/2fea9249-9370-4542-927a-c856e678f7b1.jpg
The value of Context.FilesDir.Path is /data/data/com.app.AppName/files
The image file /data/data/com.app.AppName/files/VideoData/2015-07-24-09-26-16/2fea9249-9370-4542-927a-c856e678f7b1.jpg does exist
I understand that to bind an image some custom folder determined within your app, I need to provide a path relative to Context.FilesDir.Path in order for the plugin to load it. I believe that the string in Thumbnail is correct.
But nothing is displayed in the ImageView. I have been banging my head against this one all morning. Any suggestions?
Edit :
I have managed to solve the problem !!
I needed the MvvmCross.HotTuna.Plugin.DownloadCache as well as the MvvmCross.HotTuna.Plugin.File package.
I have managed to solve the problem !!
I needed the MvvmCross.HotTuna.Plugin.DownloadCache as well as the MvvmCross.HotTuna.Plugin.File package.
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 :)
I Imported one image inside the drawable-mdpi, then implemented the image from button, but an error occurs no resource found here. How do I fix this issue?
I tried this:
main.xml
<Button
android:id="#+id/imageButtonSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable-mdpi/button_focused_orange"/>
All drawables are compiled under a single resource name, i.e. drawable. Android automatically chooses from which folder to take the drawable depending on the screen size, and hence you do not need to specifically point it out. Also, hard coding Android to use resources from a particular folder kind of defeats the purpose of having multiple folders for Android to choose from. To solve this issue, simply change:
android:background="#drawable-mdbi/button_focused_orange"/>
To
android:background="#drawable/button_focused_orange"/>
Should be #drawable/button_focused_orange
Not #drawable-mdpi/button_focused_orange
Try to clean and rebuild your project.
If you are usuing Eclipse you can do this by clicking project -> clean and then project -> Build project
You don't have to mention -mdpi to add background images, simply use drawable only. Here is you revised code. Try this.
<Button
android:id="#+id/imageButtonSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_focused_orange"/>