Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialbillwerba
8,283 PointsGetting Error on intent.getStringExtra(R.string.key-name)?
The red line on R.string.key_name, The error is; getStringExtra in Intent can not be applied to (int).
1 Answer
Andrew Sheragy
16,379 PointsThe resource file defines R.string.xx are just references to values in the string file, not actual strings. Any object with a context (including your current activity) has a function getString(int) which you would pass the parameter R.string.key-name in this case and get your string value, intent.getStringExtra(getString(R.string.key-name))
However, the strings.xml file is used for display strings only and an intent key would not be recommended for this. A better way would be defining a static final string in your class
public static final String KEY_NAME = "key-name"; ... intent.getStringExtra(KEY_NAME)