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!
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 trial

David Drees
9,219 PointsCode Challenge: All About @string Resources, Task 5 [SOLVED]
Hello Forum,
I'm failing to get past the final code challenge titled "All About @string Resources." Here is the error:
Bummer! Compilation Error!
And here is my code
Resources resources = getResources();
phoneNumberLabels = resources.getStringArray(R.array.phoneNumbers);
//String[] phoneNumberLabels = { "-home", "-work", "-mobile" };
Button saveButton = (Button) findViewById(R.id.saveButton);
String label = getString(R.string.saveLabel);
saveButton.setText(label);
The prompt is:
Update the 'phoneNumbers' variable to get its values from strings.xml instead of those already present in the code. First you need a Resources object using the 'getResources()' method and then call 'getStringArray()' from the 'resources' variable.
I'm not really sure what I'm doing wrong. A nudge in the right direction would be appreciated!
Thanks, David
5 Answers

David Kaneshiro Jr.
29,247 PointsDavid,
You still need to include 'String[]' in your phoneNumberLabels declaration.

Choong Kim
3,359 Pointsthis worked but it only worked upon removing "protect" from my declaration. In other words, I had initially declared my variable phoneNumbers as so:
protected String[] phoneNumbers;
and changed it to:
String[] phoneNumbers;
I was wondering why including protect in the declaration yields a compilation error. Thanks!

David Kaneshiro Jr.
29,247 PointsYou have to remember that this is only a code challenge so the answer it is looking for is usually going to be code that it is expecting. Even though adding 'protected' in front of the array declaration may work in XCode the challenge isn't expecting the 'protected' key word to be there. That's probably why there was a compilation error.

Juan Gallardo
1,567 PointsThe String[]
was missing in the second line. The full answer is:
Resources resources = getResources();
String[] phoneNumberLabels = resources.getStringArray(R.array.phoneNumbers);
Button saveButton = (Button) findViewById(R.id.saveButton);
String label = getString(R.string.saveLabel);
saveButton.setText(label);

Rajesh Mule
2,125 PointsResources resources = getResources(); phoneNumberLabels = resources.getStringArray(R.array.phoneNumbers);

Juan Gallardo
1,567 PointsThis does not work.

Lara Drobig
5,980 PointsHey,
your need to add the whole getRescources() method.So it's getResources().getStringArray(R.array.phoneNumbers)

Juan Gallardo
1,567 PointsYour answer is a little incomplete. Did you mean that the top 2 lines are
Resources resources = getResources();
phoneNumberLabels = getResources().getStringArray(R.array.phoneNumbers)
because that did not work
David Drees
9,219 PointsDavid Drees
9,219 PointsThanks! I will try it out now.