Hi, in my lesson Adding Images to the App on ud853 course I had a problem below.
In my case, this art function receives weatherId of DetailsFragment with value 122, 263, 356 and run a bug, because this values aren't in getArtResourceForWeatherCondition() method.
I receive weatherId with value 122 when I click on item list and redirected to DetailFragment with a bug.
FATAL EXCEPTION: main
Process: com.example.android.sunshine.app, PID: 6824
android.content.res.Resources$NotFoundException: Resource ID #0xffffffff at android.content.res.Resources.getValue(Resources.java:1266)
Code:
// DetailFragment
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
Log.v(LOG_TAG, "In onLoadFinished");
if (!data.moveToFirst()) {
return;
}
// Read weather condition ID from cursor.
int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
// Use weather art image.
mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));
...
Utility.java
/**
* Helper method to provide the art resource id according to the weather condition id returned
* by the OpenWeatherMap call.
*
* @param weatherId from OpenWeatherMap API response.
* @return resource id for the corresponding icon. -1 if no relation is found.
*/
public static int getArtResourceForWeatherCondition(int weatherId) {
// Based on weather code data found at:
// https://openweathermap.org/weather-conditions
if (weatherId >= 200 && weatherId <= 232) {
return R.drawable.art_storm;
} else if (weatherId >= 300 && weatherId <= 321) {
return R.drawable.art_light_rain;
} else if (weatherId >= 500 && weatherId <= 504) {
return R.drawable.art_rain;
} else if (weatherId == 511) {
return R.drawable.art_snow;
} else if (weatherId >= 520 && weatherId <= 531) {
return R.drawable.art_rain;
} else if (weatherId >= 600 && weatherId <= 622) {
return R.drawable.art_snow;
} else if (weatherId >= 701 && weatherId <= 761) {
return R.drawable.art_fog;
} else if (weatherId == 761 || weatherId == 781) {
return R.drawable.art_storm;
} else if (weatherId == 800) {
return R.drawable.art_clear;
} else if (weatherId == 801) {
return R.drawable.art_light_clouds;
} else if (weatherId >= 802 && weatherId <= 804) {
return R.drawable.art_clouds;
}
return -1;
}
Hi, in my lesson
Adding Images to the App
onud853
course I had a problem below.In my case, this art function receives weatherId of DetailsFragment with value 122, 263, 356 and run a bug, because this values aren't in
getArtResourceForWeatherCondition()
method.I receive weatherId with value 122 when I click on item list and redirected to DetailFragment with a bug.
https://github.com/udacity/Sunshine-Version-2/compare/5.07_details_screen...5.08_images#diff-7537c0d5330829deab3c57d11a53aa5dR219
When I click in another item:
Code:
Utility.java