Address NPEs that occur when network is disabled
This commit is contained in:
Родитель
343d3e6ea8
Коммит
7498bd67ef
|
@ -351,7 +351,7 @@ public class CardStreamLinearLayout extends LinearLayout {
|
|||
mAnimators = (CardStreamAnimator) getClass().getClassLoader()
|
||||
.loadClass(animatorName).newInstance();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Fail to load animator:" + animatorName, e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (mAnimators == null)
|
||||
mAnimators = new DefaultCardStreamAnimator();
|
||||
|
|
|
@ -35,11 +35,16 @@ public class DuckDuckGoAgent extends JsonAgent {
|
|||
|
||||
@Override
|
||||
protected CardModel createCardModel(JsonResponse response) {
|
||||
if (response == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
JSONObject responseJs = response.getResponse();
|
||||
if (responseJs == null)
|
||||
return null;
|
||||
String responseType = responseJs.getString("Type");
|
||||
Log.i("createCardModel", responseType);
|
||||
if (responseType == null)
|
||||
return null;
|
||||
/**
|
||||
* Type: response category, i.e.
|
||||
* A (article),
|
||||
|
@ -55,7 +60,7 @@ public class DuckDuckGoAgent extends JsonAgent {
|
|||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e("createCardModel", e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,9 @@ public class ForecastIoAgent extends JsonAgent {
|
|||
}
|
||||
|
||||
private WeatherModel initWeatherObject(JSONObject apiResponse) {
|
||||
if (apiResponse == null) {
|
||||
return null;
|
||||
}
|
||||
WeatherModel model = null;
|
||||
try {
|
||||
JSONObject currentStatus = apiResponse.getJSONObject("currently");
|
||||
|
@ -63,7 +66,7 @@ public class ForecastIoAgent extends JsonAgent {
|
|||
model = new WeatherModel(currentTemp, currentCondition);
|
||||
|
||||
} catch (JSONException e) {
|
||||
LOGGER.log(Level.SEVERE, "jsonMemberError", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
@ -95,7 +98,7 @@ public class ForecastIoAgent extends JsonAgent {
|
|||
model.pushForecast(builder.createWeatherForecast());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
LOGGER.log(Level.SEVERE, "jsonMemberError", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,7 +106,11 @@ public class ForecastIoAgent extends JsonAgent {
|
|||
@Override
|
||||
protected WeatherModel createCardModel(JsonResponse response) {
|
||||
JSONObject apiResponse = response.getResponse();
|
||||
if (apiResponse == null)
|
||||
return null;
|
||||
WeatherModel model = initWeatherObject(apiResponse);
|
||||
if (model == null)
|
||||
return null;
|
||||
pushForecasts(model, apiResponse);
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public abstract class HttpAgent<T> extends AsyncTask<Query, Void, T> {
|
||||
|
||||
|
@ -102,7 +103,7 @@ public abstract class HttpAgent<T> extends AsyncTask<Query, Void, T> {
|
|||
try {
|
||||
model = createCardModel(result);
|
||||
} catch (JSONException e) {
|
||||
Log.e("onPostExecute", e.toString());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
IsCard card = null;
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class JsonAgent extends HttpAgent<JsonResponse> {
|
|||
try {
|
||||
json = new JSONObject(jsonStr);
|
||||
} catch (JSONException e) {
|
||||
Log.e("JsonParseError", e.toString());
|
||||
e.printStackTrace();
|
||||
return JsonResponse.failure("Failed to parse JSON response.");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class Query {
|
|||
try {
|
||||
mQueryString = URLEncoder.encode(query, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e("Unable to encode query as utf8", query);
|
||||
e.printStackTrace();
|
||||
mQueryString = "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public class WikipediaAgent extends JsonAgent {
|
|||
}
|
||||
return model;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ public class YelpAgent extends JsonAgent {
|
|||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return model;
|
||||
|
|
|
@ -45,14 +45,10 @@ public class YqlReverseGeocodeAgent extends JsonAgent {
|
|||
protected CardModel createCardModel(JsonResponse response) {
|
||||
try {
|
||||
JSONObject jsAddr = response.getResponse().getJSONObject("query").getJSONObject("results").getJSONObject("Result");
|
||||
Log.i("city", jsAddr.getString("city"));
|
||||
Log.i("state", jsAddr.getString("state"));
|
||||
Log.i("neighborhood", jsAddr.getString("neighborhood"));
|
||||
Log.i("woeid", jsAddr.getString("woeid"));
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e("createCardModel", e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i("Yql", response.getResponse().toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ public class AutoCompleteService {
|
|||
receiver.send(STATUS_OK, results);
|
||||
}
|
||||
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class FlickrService extends AsyncTask<Query, Void, String> {
|
|||
List<String> urls = getUrls(fetch(buildUrl(queries[0])));
|
||||
return urls.size() > 0 ? urls.get(0) : null;
|
||||
} catch (JSONException e) {
|
||||
Log.e("doInBackground", e.toString());
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче