I am developing an android app, I am trying to use the android image button. I have placed my image in the drawable folder and have this in my xml code:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/PanicBtn"
android:layout_marginTop="53dp"
android:src="#drawable/panicbtn2"
android:background="#ffffffff"
android:contentDescription="" />
but each time I try to clean or debug the project, i keep getting this error:
Error:(28, 22) No resource found that matches the given name (at 'src' with value '#drawable/panicbtn2').
Kindly help.
Sometimes, keeping the resource or image in your case in Drawable folder doesn't get added to ItemGroup/resource group.
You can simply open the .csproj file of your project and validate that if the image name is present in the < ItemGroup > section.. it must be like below if your image name and extension is panicbtn2.png:
<AndroidResource Include="Resources\drawable\panicbtn2.png" />
If it's not present there, then you can add the same there or you can right click the drawable folder and choose add files and simply add the file again through IDE/Visual Studio. That might help.
The error already states:
No resource found that matches the given name
Have you place a resource in drawable with that specific name "panicbtn2"?
Cheers.
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
I have an project that I put all of my images for the system in the workspace.
I have this at the top of my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:images="http://schemas.android.com/apk/res/com.utas.android.imagelibrary"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_blue"
android:padding="8dip"
>
The namespace "images" gives a warning in Eclipse stating "unused names space images", which leads me to believe I am atleast doing that part right but the next part is wrong.
With in my ImageLibrary (a project that has the "Is Library" check boxed checked in the same workspace) I have the following pathing
res/drawable/01_core_accept/drawable-hdpi/ic_action_acept.png
I have a button within the layout as follows.
<Button
android:id="#+id/btn_finish_a"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/btn_finish_a_label"
android:layout_toRightOf="#id/btn_start_c"
android:icon="#images:res/drawable/01_core_accept/drawable-hdpi/ic_action_acept"
android:onClick="finishActivityA"
/>
However I am getting an error on the image reference stating "error:Error:No resource found that matches the given name (at 'icon' with value '#images:res/drawable/01_core_accept/drawable-hdpi/ic_action_acept')."
How do I properly reference an image in an external?
You do not need this line:
xmlns:images="http://schemas.android.com/apk/res/com.utas.android.imagelibrary"
The line should read:
android:icon="#drawable/ic_action_acept"
If you've linked an Android Library project correctly, resources defined in that library should be compiled into your app and you reference the same way as resources in your own res folders.
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)
I currently have a code for a button in XML as such:
<Button
android:id="#+id/button1"
android:layout_width="250dp"
android:layout_height="62dp"
android:layout_gravity="center_horizontal"
android:drawableLeft="#drawable/ic_menu_slideshow"
android:text="Start Slideshow" />
However, I get an error for Error: No resource found that matches the given name (at 'drawableLeft' with value '#drawable/ic_menu_slideshow'). However, when I check on the graphical layout of the XML file, the stock drawable at ic_menu_slideshow is present. Why do I get this compilation error, and how would I fix it?
Try to replace #drawable/ic_menu_slideshow with #android:drawable/ic_menu_slideshow
Have you tried cleaning your project? A similar question was asked moments ago so keep an eye on that as well: Can't Resolve Android Resource Strings
Ok, I have been following a lesson sample at the Android Developer site and the code was thus:
<LinearLayout 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:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
Apparently, the code should be fine, after worrying I typed it in wrong, I ended up copying it directly but the Console is telling me:
Description
error: Error: No resource found that matches the given name (at 'hint' with value '#string/edit_message').
Description
error: Error: No resource found that matches the given name (at 'text' with value '#string/button_send').
Now these values are defined in the strings.xml file. So I have no idea why I would be getting these errors.
To anyone who can help here is a big thank you in advance.
Try in eclipse project>clean . Sometimes eclipse give you errors like these. Or restart eclipse. Did you also make sure at your strings.xml you have something like this ?<string name="edit_message">Your intresting string.</string> sometimes if you use the 'gui resource adder' It gives mistakes. Check inside your xml.
make sure there is no capital characters or underscores in any file inside res.
Also , there must no any error inside the files of res and src ..
after that you have to clean the project as mentioned in previous answer.
Actually these errors prevent the R file to be updated which is necessary to access resources inside res file.