Skip to content

Commit

Permalink
Fix NPE when app has low battery
Browse files Browse the repository at this point in the history
Check for null object from http client getReponse method call.
This is a quick way to fix the NPE. In the future investigate
why the getReponse call returns null.
  • Loading branch information
eyedol committed Feb 13, 2016
1 parent 61c35e5 commit a1f2224
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void lowBatteryLevelRequest(int batteryLevel) {
.syncGetByStatus(WebServiceEntity.Status.ENABLED);
if (!Utility.isEmpty(webServiceEntities)) {
for (WebServiceEntity webServiceEntity : webServiceEntities) {
mAppHttpClient.setUrl(webServiceEntity.getUrl());
mAppHttpClient.addParam(TASK_PARAM, "alert");
mAppHttpClient.addParam(MESSAGE_PARAM, mContext.getResources()
.getString(R.string.battery_level_message, batteryLevel));
Expand All @@ -90,7 +91,8 @@ public void lowBatteryLevelRequest(int batteryLevel) {
} catch (Exception e) {
mFileManager.appendAndClose(e.getMessage());
} finally {
if (200 == mAppHttpClient.getResponse().code()) {
if ((mAppHttpClient.getResponse()) != null && (200 == mAppHttpClient
.getResponse().code())) {
mFileManager.appendAndClose(
mContext.getResources()
.getString(R.string.successful_alert_to_server));
Expand All @@ -113,6 +115,7 @@ public void smsSendFailedRequest(String resultMessage,
List<WebServiceEntity> webServiceEntities = mWebServiceRepository.syncGetByStatus(
WebServiceEntity.Status.ENABLED);
for (WebServiceEntity webServiceEntity : webServiceEntities) {
mAppHttpClient.setUrl(webServiceEntity.getUrl());
mAppHttpClient.addParam(TASK_PARAM, "alert");
mAppHttpClient.addParam(MESSAGE_PARAM, resultMessage);
if (!errorCode.matches("")) {
Expand Down

0 comments on commit a1f2224

Please sign in to comment.