Reputation: 1559
simple question . I got this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">YYYYYY</string>
<string name="leaderBoard">XXXXX</string>
</resources>
in my res>values>strings.xml
Then in my Activity I try to pull out the leaderBoard value but java refuses to do so.
String string = getString(R.string.leaderBoard);
leaderBoard cannot be resolved into a field.
I have tried , cleaning up project , refreshing , still nothing. On the other hand I am able to retrieve app_name into an xml file like the manifest.xml . I m pretty sure that I m blind or something...
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
...
Upvotes: 0
Views: 947
Reputation: 15668
Make sure you are using the correct R class - the one of your project, not android's. Check the imports.
It should be something like this
import com.yourapp.R;
and not like
import android.R;
Upvotes: 2
Reputation: 75798
You need to read string form String.xml so you can use getString()
which is the method of resource so you will get your output Now.
getResources().getString(R.string.YOUR_XML_STRING);
If not works Please Clean & Rebuild
your project
For More Info. You may visit
http://developer.android.com/guide/topics/resources/string-resource.html And http://developer.android.com/reference/android/content/Context.html#getString%28int%29
Upvotes: 2
Reputation: 170
Change to this
getResources().getString(R.string.leaderBoard);
Upvotes: 0