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 trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Using String Resources

String resources can be used throughout an app. In this challenge we want to use a String resource to set the text of a

any help I tried many thong to solve this but non of them worked as he asked ,so what I am missing here ??~~

String resources can be used throughout an app. In this challenge we want to use a String resource to set the text of a Button. Switch to the strings.xml file and add a new String item named morePuppies with the value "See More Puppies".

CodeChallenge.java
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = "see More puppies";
loadPuppiesButton.setText("LOAD");
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string  name="SeeMorePuppies">MorePuppies</string>
</resources>

6 Answers

Jason Thorn
Jason Thorn
2,611 Points

Hi Ahmed, Sorry I wasn't paying attention to the challenge.

It looks like your strings.xml is incorrect. It should look like this (as per the challenge)

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="morePuppies">See More Puppies</string>
</resources>

and your calling code should be (as per my last response):

Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = getString(R.string.morePuppies);
loadPuppiesButton.setText("LOAD");

Hope this helps Anymore questions... just ask :)

what about the second code ?? It's wrong ??

Jason Thorn
Jason Thorn
2,611 Points

These two snippits well get you though the first two questions on the code challenge (tested myself). Which part are you having problems with?

the second one I putted the same code and it said that con't find symbol for the morePuppies ???

Jason Thorn
Jason Thorn
2,611 Points

Did you update your Strings.xml to :

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="morePuppies">See More Puppies</string>
</resources>
Neil Gordon
Neil Gordon
8,823 Points

thanks for the explanation I had mine backwards this was a big help

AHHHHH... i tried all the code that was provided here but it seems that its not working...im smashing my face in the keyboard because of the irritation i feel in this code challenge.. even if i put up the correct answer which is provided in this section...it stills displays the error saying Don't forget to add a 'name' attribute to your <string> element with the value "morePuppies" even if i declare the value on the <string name="morePuppies"> See More Puppies </string>

Jason Thorn
Jason Thorn
2,611 Points

Hi Albert

Take a step back and relax! We're all here to help :)

Could you post your code so we can check through it.

Graeme Coppinger
Graeme Coppinger
999 Points

thanks for the question I think you have the wrong student

String buttonLabel = getString(R.string.morePuppies);

not

String buttonLabel = getString(R.string.SeeMorePuppies);

This is why he kept getting the problem incorrect, the OP was typing the error that Jason Thorn overlooked.

<?xml version="1.0" encoding="utf-8"?> <resources> <string name="morePuppies">See More Puppies</string> </resources>

Jason Thorn
Jason Thorn
2,611 Points

Hi Ahmed

To access string resources you need to use the following:

 getString(R.string.YOUR_STRING_NAME);

So your code should look something like:

Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = getString(R.string.SeeMorePuppies);
loadPuppiesButton.setText("LOAD");

ammmmm still wrong ?? also I want to wright the code in String.XML