From d994cd318d79a59090790412ca7f095847d56165 Mon Sep 17 00:00:00 2001 From: Aaron Hastings Date: Wed, 22 Mar 2017 20:33:55 +0000 Subject: [PATCH] [Mobile] Added safety check to Retrofit response processing code. --- .../luasataglance/activity/LineFragment.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mobile/src/main/java/org/thecosmicfrog/luasataglance/activity/LineFragment.java b/mobile/src/main/java/org/thecosmicfrog/luasataglance/activity/LineFragment.java index dad53eb..487a73a 100644 --- a/mobile/src/main/java/org/thecosmicfrog/luasataglance/activity/LineFragment.java +++ b/mobile/src/main/java/org/thecosmicfrog/luasataglance/activity/LineFragment.java @@ -801,17 +801,20 @@ private void loadStopForecast(String stopName) { public void success(ApiTimes apiTimes, Response response) { /* Check Fragment is attached to Activity to avoid NullPointerExceptions. */ if (isAdded()) { - /* Then create a stop forecast with this data. */ - StopForecast stopForecast = StopForecastUtil.createStopForecast(apiTimes); + /* If the server returned times. */ + if (apiTimes != null) { + /* Then create a stop forecast with this data. */ + StopForecast stopForecast = StopForecastUtil.createStopForecast(apiTimes); - clearStopForecast(); + clearStopForecast(); - /* Update the stop forecast. */ - updateStopForecast(stopForecast); + /* Update the stop forecast. */ + updateStopForecast(stopForecast); - /* Stop the refresh animations. */ - setIsLoading(false); - swipeRefreshLayout.setRefreshing(false); + /* Stop the refresh animations. */ + setIsLoading(false); + swipeRefreshLayout.setRefreshing(false); + } } }