From fd0b5e6f9b13bb7407af1df4e54ab4ceb0091f2f Mon Sep 17 00:00:00 2001 From: oliexdev Date: Wed, 18 Jul 2018 20:30:38 +0200 Subject: [PATCH] catch error if polygon degree of regression line is empty (fixed bug #306) --- .../openscale/gui/fragments/GraphFragment.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java index 43d21dcc..954cf324 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java @@ -37,6 +37,7 @@ import android.widget.LinearLayout; import android.widget.PopupMenu; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import com.health.openscale.R; import com.health.openscale.core.OpenScale; @@ -321,9 +322,16 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { floatingActionBar.removeAllViews(); - PolynomialFitter polyFitter = new PolynomialFitter( - Math.min(Integer.parseInt(prefs.getString("regressionLineOrder", "1")), - 100)); + int regressLineOrder = 1; + + try { + regressLineOrder = Integer.parseInt(prefs.getString("regressionLineOrder", "1")); + } catch (NumberFormatException e) { + Toast.makeText(getContext(), getString(R.string.error_value_required) + ":" + e.getMessage(), Toast.LENGTH_LONG).show(); + prefs.edit().putString("regressionLineOrder", "1").commit(); + } + + PolynomialFitter polyFitter = new PolynomialFitter(Math.min(regressLineOrder, 100)); for (MeasurementView view : measurementViews) { if (view instanceof FloatMeasurementView) {