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 trialahmed alghafli
3,446 PointsString 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".
Button loadPuppiesButton = (Button) findViewById(R.id.puppiesButton);
String buttonLabel = "see More puppies";
loadPuppiesButton.setText("LOAD");
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="SeeMorePuppies">MorePuppies</string>
</resources>
6 Answers
Jason Thorn
2,611 PointsHi 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 :)
albert gregorio
Courses Plus Student 866 PointsAHHHHH... 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
2,611 PointsHi 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
999 Pointsthanks for the question I think you have the wrong student
Erick Ramirez
1,633 PointsString 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.
Jamal Shiekh
6,440 Points<?xml version="1.0" encoding="utf-8"?> <resources> <string name="morePuppies">See More Puppies</string> </resources>
Jason Thorn
2,611 PointsHi 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");
ahmed alghafli
3,446 Pointsammmmm still wrong ?? also I want to wright the code in String.XML
ahmed alghafli
3,446 Pointsahmed alghafli
3,446 Pointswhat about the second code ?? It's wrong ??
Jason Thorn
2,611 PointsJason Thorn
2,611 PointsThese two snippits well get you though the first two questions on the code challenge (tested myself). Which part are you having problems with?
ahmed alghafli
3,446 Pointsahmed alghafli
3,446 Pointsthe second one I putted the same code and it said that con't find symbol for the morePuppies ???
Jason Thorn
2,611 PointsJason Thorn
2,611 PointsDid you update your Strings.xml to :
Neil Gordon
8,823 PointsNeil Gordon
8,823 Pointsthanks for the explanation I had mine backwards this was a big help