From 0c82456897789e8ba25e5256094c1bc681f44dca Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 21 Mar 2022 20:27:17 -0700 Subject: [PATCH] Fixed highlight null pointer exception Moved the null pointer check to before that pointer was actually being used. Fixes null pointer exception when removing a dataset from the chart after highlighting a data point on that dataset. --- .../java/com/github/mikephil/charting/charts/Chart.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java index 5cf49ea9d1..1204f78288 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java @@ -791,10 +791,14 @@ protected void drawMarkers(Canvas canvas) { IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex()); Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]); + + // make sure entry not null before using it + if (e == null) + continue; + int entryIndex = set.getEntryIndex(e); - // make sure entry not null - if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX()) + if (entryIndex > set.getEntryCount() * mAnimator.getPhaseX()) continue; float[] pos = getMarkerPosition(highlight);