From 2c2d83707928b765f4a383f60274d26edc62887d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 9 Mar 2017 10:20:38 +0100 Subject: [PATCH] fix null pointer exception --- .../info/nightscout/androidaps/db/TempBasal.java | 6 +++++- .../plugins/NSClientInternal/data/NSProfile.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java index d15ab436da..149d188b7c 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java @@ -59,11 +59,15 @@ public class TempBasal { if (profile == null) return result; + Double basalRate = profile.getBasal(profile.secondsFromMidnight(time)); + + if (basalRate == null) + return result; + int realDuration = getRealDuration(); if (realDuration > 0) { Double netBasalRate = 0d; - Double basalRate = profile.getBasal(profile.secondsFromMidnight(time)); Double tempBolusSize = 0.05; if (isExtended) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java index 4d3df3068c..5ff95ddf39 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; +import android.support.annotation.Nullable; + import com.crashlytics.android.Crashlytics; import org.json.JSONArray; @@ -178,6 +180,7 @@ public class NSProfile { return TimeZone.getDefault(); } + @Nullable public Double getValueToTime(JSONArray array, Integer timeAsSeconds) { Double lastValue = null; @@ -221,10 +224,12 @@ public class NSProfile { return retValue; } + @Nullable public Double getIsf(Integer timeAsSeconds) { return getIsf(getDefaultProfile(), timeAsSeconds); } + @Nullable public Double getIsf(JSONObject profile, Integer timeAsSeconds) { if (profile != null) { try { @@ -251,10 +256,12 @@ public class NSProfile { return ""; } + @Nullable public Double getIc(Integer timeAsSeconds) { return getIc(getDefaultProfile(), timeAsSeconds); } + @Nullable public Double getIc(JSONObject profile, Integer timeAsSeconds) { if (profile != null) { try { @@ -281,10 +288,12 @@ public class NSProfile { return ""; } + @Nullable public Double getBasal(Integer timeAsSeconds) { return getBasal(getDefaultProfile(), timeAsSeconds); } + @Nullable public Double getBasal(JSONObject profile, Integer timeAsSeconds) { if (profile != null) { try { @@ -339,10 +348,12 @@ public class NSProfile { return ""; } + @Nullable public Double getTargetLow(Integer timeAsSeconds) { return getTargetLow(getDefaultProfile(), timeAsSeconds); } + @Nullable public Double getTargetLow(JSONObject profile, Integer timeAsSeconds) { if (profile != null) { try { @@ -354,10 +365,12 @@ public class NSProfile { return 0D; } + @Nullable public Double getTargetHigh(Integer timeAsSeconds) { return getTargetHigh(getDefaultProfile(), timeAsSeconds); } + @Nullable public Double getTargetHigh(JSONObject profile, Integer timeAsSeconds) { if (profile != null) { try {