Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Cihan Kaptan
Cihan Kaptan
2,819 Points

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?

Alexander Schott
Alexander Schott
8,318 Points

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

3 Answers

Check the import statement...

Connor Myers
Connor Myers
21,089 Points

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 :)

Cihan Kaptan
Cihan Kaptan
2,819 Points

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