Reputation: 24500
I learn android with sample apps from textbook. In the given sample source R.string.something is recognized:
However, in my own EXACT source code, same R.strings are not recognized- highlighted as errors:
Does anyone know how to fix it?
Upvotes: 1
Views: 1993
Reputation: 1
Cleaning or building the project didn't help me. Restarting the IDE did it in my case.
Upvotes: 0
Reputation: 1859
I assume you are new to Android.
If so, there are two ways of using text strings in Buttons, textviews and so on:
1) Hardcoded string - you put the text you want in quotation marks (""), for example:
yourTextview.setText("Hardcoded string");
2) You can call the text from your String resources (res/values/strings.xml). That is a much better approach seeing is is easier to translate, make changes and so on.
In your strings.xml
file you can create all your string values, and call them from there.
Like in you example, if in your strings.xml
file you have for example:
<string name="delete">This is String resource</string>
you can then call the string from there, like so :
yourTextview.setText(R.string.delete);
Hope this helps!
Upvotes: 1
Reputation: 2504
I've had this many time with eclipse, and it was not a setup / code problem on my side. Generally, cleaning, rebuilding and sometime even stopping and restarting eclipse solved it. And yes, it's a pain in the neck ...
Upvotes: 1
Reputation: 4258
These are following reason possible.
1-: You import android.R;
2-: Any error in xml files.
3-: Please check you String.xml file may be any error or declare a string more then two time.
Upvotes: 2
Reputation: 632
Try a clean of your project, if that does nothing then click on the problems tab and see if there's any build related issues, you may be missing a required jar or something!
Upvotes: 1