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

How to get Android Resources to Main Activity

Resources res = getResources(); final String[] array = res.getStringArray(R.array.facts_array);

This codes is working at Eclipse but Android Studio is giving Error for getResources() method ?

what is the error?

same problem here, unresolved method. It can't find the getResources() method.

3 Answers

Check the import statement...

You can chain them all together and get rid of the resources variable like this:

String[] array = getResources().getStringArray(R.array.facts_array);

Don't know if this is going to change anything but It will help your code to look a little cleaner :)

There isnt any problem about imports. Everything is same at two tools but Android Studio doesnt let use getResources() method