So I'm building a game in Android, and I have just created a huge XML file. When I switch to graphical layout in ADT, I'm getting the right layout, so no problems there.
But below the graphical layout, There are two messages:
Couldn't resolve resource #drawable/ic_launcher
Couldn't resolve resource #string/app_name
I have no idea what is causing these problems, as both words ic_launcher and app_name are not found anywhere in my XML.
But I found ic_launcher in all *hdpi folder under res/drawable/ and the string app_name was in res/values/string.xml
Should I have entered XML tags somewhere inside my code? If so, can you please tell me under which tag it should be?
[My XML is composed entirely of nested LinearLayouts and Buttons]
Thanks!
Make sure you don't have errors in other resources (layouts, values, drawables, etc.).
And then clean/refresh/build the project
Related
I have made a new value resource file in the android studio project as name dimens
but while referring to it from XML I have to use the attribute #dimen
I am really curious to know the referring tag must have to be the same as the file name but it is not.
I have seen the same pattern in strings and colors.
But it is like that? any clue?
name of your files doesn't matter in fact, you can rename dimens.xml to anything.xml. Or you can have dimen_activity.xml and dimen_fragment.xml files, which helps you manage them. Also, you can keep in this file <dimen tags, but also <integers and any other (e.g. you can have one sizes.xml file). Resources are built upon content inside all XML files placed in values, a kind-of map is created then and all <dimens from all XML files are available under #dimen/ or R.dimen.
I have encountered the following issue in Android Studio: when I select the "..." to specify the source drawable file for an ImageView, in the Project tab I don't see the project drawables, even if they do appear into the drawable folder on the left pane, but instead a long list of (I guess) system drawables (whose name is starting with "abc_") and no trace of the custom files I have successfully pasted into the project drawable folders.
If I try to write manually a reference to the correct resource in XML (android:src="#drawable/main_title"), I get the following error popup:
Rendering Problems Couldn't resolve resource #drawable/main_title. Failed to convert #drawable/main_title into a drawable.
Does anybody have any idea of what's happened? Thank you in advance.
You're trying to put in android:src a string, not a Drawable. If you want to apply drawable to your ImageView src you should use somthing like this:
android:src="#drawable/your_image_drawable"
I just found my own mistake: I pasted the drawable files inside the drawable folder, while they must reside inside the res folder. Now it works.
Thanks for your replies.
I have an imageView in my main.xml file, that isn't setup with a source initially. I want to be able to dynamically change the image resource within the code. so lets so i have my imageView setup like this:
<ImageView
android:id="#+id/countryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/CountryImageContent"/>
So i try to access within my code like this:
ImageView img = (ImageView) findViewById(R.id.countryImage);
The problem is here. Eclipse is giving me an error saying that "countryImage cannot be resolved or is not a field". A quick peek into my R.java file is showing me that the imageView isn't actually in there. Why is this happening? Thanks.
look into your drawable and layout if there is any error
if not try cleaning your project
Go to Project > clean > select your project
if not then look into your imports for
your.packagename.R remove it
Project -> Clean.
That is the only solution to this.
Also make sure that among your import statements, you do not have this : import android.R
Check this link for a detailed procedure.
Note : I am assuming that there are no errors in your layout and drawable files, as errors in them may also lead to this problem.
make sure all resource files have only lowercase letters , numbers and the underscore character ("_") .
only if there are no errors in creating the R file (in the "gen" folder) , you can use the id of it.
I think it is the problem to giving the name of #string
Please Remove all UpperCase Character from #string/CountryImageContent and replace it with small character.
R.java file doesn't support any Uppercase character. It gives the same error when you declare the file name of any resources Like :- Image, XML, #string, etc...
Just rename CountryImageContent with country_image_content. it will work perfect.
Another option to try in this case is: File --> Invalidate Caches / Restart...
When I am editing a layout file is there a way to get eclipse to autocomplete my strings references from strings.xml.
For example if I have a layout node like this...
<PreferenceCategory android:title="#string/settings_category_stay_intouch_title">
It would be great if I could type the #string/settings_ part and then use alt+space like I can when I referencing the R.string in a source file.
Right now I just get "No XML Template Proposal"
Any tips for configuration or plugins would be appreciated. I use strings.xml extensively and I have a ton of layout files so flipping back and forth between strings.xml and my layouts as I work on them is a bummer.
Well it should work. Try using on windows CTL+space.
I tested with latest ADT 16.
I am teaching myself Android using Eclipse, the Android plug-in, and Sams "Teach Yourself Android Development" book. I have this weird little problem. I've been able to create xml files in the res/values directory that hold strings and color values (colors.xml and strings.xml). I have been able to reference these values in the properties of my Android screens (the xml in res/layout), for example setting the "Text" and "Text color" properties with references like "#string/topTitle" and "#color/titleColor," where topTitle and titleColor are defined in the xml files.
BUT: when I create a file called "dimens.xml" and have font sizes in it, Eclipse correctly puts this file in res/values, but when I try to reference these values, e.g. "#dimension/titleFont" I get an error "No resource found that matches the given name." I've tried lots of different names, I've tried "#dimens" instead of the type, still nothing. If I go into the layout xml file and set it explicitly to a font size, e.g. 22pt, it works.
So Eclipse recognized my "dimens.xml" file when I made it well enough to put it in res/values, and lets me edit it, and shows it full of (dimension) values. It just doesn't recognize my referring to it in other xml files.
The book I'm using doesn't actually show a dimension example so I must be doing something wrong. I checked the Android docs but couldn't see any problem.
Any help appreciated. Thanks.
The correct way to refer to a dimension variable (stored in your dimens.xml (don't think the name here really matters though, it's what's inside that does)) from another xml file is like this:
"#dimen/nameOfVariable"
Notice that it is neither dimension, dimensions or dimens, but dimen!
If you look inside your xml file where you have your values, this will make sense as dimen is the name of the xml elements storing dimension values:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<dimen name="someDimension">5dp</dimen>
<dimen name="anotherDimension">10dp</dimen>
</resources>