Skip to content

Commit 8ca9103

Browse files
authored
Merge pull request #267 from AppDevNext/PreventNPE
Prevent NPE
2 parents 00656b3 + bc39f3f commit 8ca9103

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,12 +809,13 @@ public String getAccessibilityDescription() {
809809

810810
PieData pieData = getData();
811811

812-
int entryCount = pieData.getEntryCount();
812+
int entryCount = 0;
813+
if (pieData != null)
814+
entryCount = pieData.getEntryCount();
813815

814816
StringBuilder builder = new StringBuilder();
815817

816-
builder.append(String.format(Locale.getDefault(), "The pie chart has %d entries.",
817-
entryCount));
818+
builder.append(String.format(Locale.getDefault(), "The pie chart has %d entries.", entryCount));
818819

819820
for (int i = 0; i < entryCount; i++) {
820821
PieEntry entry = pieData.getDataSet().getEntryForIndex(i);

MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.github.mikephil.charting.formatter.IValueFormatter;
77
import com.github.mikephil.charting.utils.MPPointF;
88

9+
import androidx.annotation.Nullable;
10+
911
/**
1012
* Interface that provides everything there is to know about the dimensions,
1113
* bounds, and range of the chart.
@@ -53,6 +55,7 @@ public interface ChartInterface {
5355

5456
IValueFormatter getDefaultValueFormatter();
5557

58+
@Nullable
5659
ChartData getData();
5760

5861
int getMaxVisibleCount();

0 commit comments

Comments
 (0)