I am using this code to pull my string array from my values folder:
String achievementNames[] = getResources().getStringArray(R.array.achieveString);
String achievementDescriptions[] = getResources().getStringArray(R.array.achieveDescript);
However, when I run this, it gives me a null pointer exception on those lines of code. Is there a better way to pull string arrays or is there an error in my code?
Make sure you pass a
Context
object to wherever you call this method from (as my guess is thatgetResources()
is returningnull
). With thisContext
object, you can call,You shouldn't call
getResources()
unlessonCreate()
callback has been triggered.