Skip to content

Commit bc39f3f

Browse files
committed
Prevent NPE
1 parent 0a3ceb6 commit bc39f3f

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.
@@ -63,6 +65,7 @@ public interface ChartInterface {
6365

6466
IValueFormatter getDefaultValueFormatter();
6567

68+
@Nullable
6669
ChartData getData();
6770

6871
int getMaxVisibleCount();

0 commit comments

Comments
 (0)