Good day, Any idea why i could be getting a NullPointerException in the following code. I am trying to retrieve elements from a string-array in XML and test against a given value but i keep getting a NullpointerException on the first line of the code below.
String [] position = context.getResources().getStringArray(R.array.google_weather_conditions); // NullpointerException here
for(String check: position){
String test_condition = check;
if(this.condition.equals(test_condition)){
weather_conditions = test_condition;
}
}
here is the strings.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Clear">Clear</string>
<string name="Sunny">Sunny</string>
<string name="Mostly_Sunny">Mostly Sunny</string>
<string name="Partly_Sunny">Partly Sunny</string>
<string name="Cloudy">Cloudy</string>
<string name="Mostly_Cloudy">Mostly Cloudy</string>
<string name="Partly_Cloudy">Partly Cloudy</string>
<string name="Rain">Rain</string>
<string-array name="google_weather_conditions">
<item>@string/Clear</item>
<item>@string/Sunny</item>
<item>@string/Mostly_Sunny</item>
<item>@string/Partly_Sunny</item>
<item>@string/Cloudy</item>
<item>@string/Mostly_Cloudy</item>
<item>@string/Partly_Cloudy</item>
<item>@string/Rain</item>
</string-array>
</resources>
Most likely
contextis null at the point of the NPE.