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

Victoriano Torrens Alfonso
2,425 PointsAdding a String array
I'm trying to add the "string-array" to the Fun facts project, but I don't know to get the content of the string-array that I have created in the XML file. I have added this code: " Resources res = FunFactsActivity.getResources(); public String[] mfacts = res.getStringArray(R.array.fact_book_array);"
But I'm still getting this error:"Error:(14, 37) error: non-static method getResources() cannot be referenced from a static context"
2 Answers

Ratik Sharma
32,885 PointsUse the following to get the string array from the resources:
mFacts = getResources().getStringArray(R.array.fact_book_array);

Victoriano Torrens Alfonso
2,425 PointsI have solved it calling the getResources() function from the main class, and sending the value to the subprogramme builded on the second class.
Victoriano Torrens Alfonso
2,425 PointsVictoriano Torrens Alfonso
2,425 PointsIt says "Can't resolve method getResources()" I think this is because I'm calling the get resources(), from a class that it's not the main class. And if I assign the FunFactsActivity class at the begging of the sentence I get the mentioned error.