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 Introducing String Resources

Alexander Schott
Alexander Schott
8,318 Points

Unresolved Method getStringArray()

I started facing the extraCredit challenge on my Fun Facts project to set a ressource string array for the facts. All done but the problem is that Android studio can't find the method getStringArray(). It doesn't import the right libaries etc. What can I do?

I already tried File -> Invalid Caches / Restart... change build.gradle from *.jar to *.class

The strange effect is, that if I am in my main class FunFactsActivity, then the autoimport and completion works for getString(), but if I am in the FactBook.java class then even getString() will not be found. getStringArray() did not work for both. I use the latest version of Android Studio V 1.1.0. Probably my Java SDK is corrupted or my library?

If autoimport didn't work, have you tried typing it in manually?

Alexander Schott
Alexander Schott
8,318 Points

Sure then the unresolved error message appears.

Harry James
Harry James
14,780 Points

Hmm. Try a Clean Project under the Build tab and see if that makes any difference.

If not, what are you extending in your classes and what is your Android SDK version you're using?

Alexander Schott
Alexander Schott
8,318 Points

22 Update i have reinstalled android studio and I used an older version. Now I find getResources().getStringArray()

My next problem is, that android studio dont find getResources()... in my selfdefined java classes. If i inherit the ActionBarActivity class, then the methods will be found, because in the main class the libraries are imported. I can't import the right "android.support.v7.app.ActionBarActivity;" librarie by myself, Android Studio will discard it every time I want to import it and the getResources().getStringArray() method won't be found.

1 Answer

Alexander Schott
Alexander Schott
8,318 Points

I used this treehouse forum thread to fix my issue. The trick is to inherit the ContextWrapper class in your FactBook class and build a constructor with super(base) and base is a Context Object. It works now, but I dont understand why i can't simply use getResources() :-( any help?

Harry James
Harry James
14,780 Points

Hmm... I can't understand this either as it should work.

If you would like me to look into it a bit more, feel free to send me your project (Copy the project folder from its directory, upload it to an online storage service and put the link to it here) and I'll take a look whether it works fine on my side and whether I can figure out what's causing this (Whether its a project issue or a configuration issue).