From 017dba397ff77d5289b9fdb8dd3863e682fd2d7c Mon Sep 17 00:00:00 2001 From: Area128 Date: Tue, 18 Dec 2018 14:01:20 +0100 Subject: [PATCH] Fix java.lang.StringIndexOutOfBoundsException. Check if the string is long enough first. --- Telemetry Viewer/src/ChartUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Telemetry Viewer/src/ChartUtils.java b/Telemetry Viewer/src/ChartUtils.java index d3b09c7..c58ab7f 100644 --- a/Telemetry Viewer/src/ChartUtils.java +++ b/Telemetry Viewer/src/ChartUtils.java @@ -270,8 +270,11 @@ public static String formattedNumber(double number, int digitCount) { String text = String.format("%.9f", number); int pointLocation = text.indexOf('.'); int stringLength = text.charAt(0) == '-' ? digitCount + 2 : digitCount + 1; - return text.substring(0, pointLocation < stringLength ? stringLength : pointLocation); - + if(text.length() > (pointLocation < stringLength ? stringLength : pointLocation)){ + return text.substring(0, pointLocation < stringLength ? stringLength : pointLocation); + } else { + return text.substring(1, text.length()); + } } /**