There is a code to add positions to the array and display the graph in GraphView:
for (i = 0; i < FragmentDiaryWeight.weightDiaryList.size(); i++) { if (FragmentDiaryWeight.weightDiaryList.get(i).getmMonth() == 3) { weightDiaryListSorted.add(new WeightDiaryClass( FragmentDiaryWeight.weightDiaryList.get(i).getmDate(), FragmentDiaryWeight.weightDiaryList.get(i).getmWeight(), FragmentDiaryWeight.weightDiaryList.get(i).getmImt(), FragmentDiaryWeight.weightDiaryList.get(i).getmDay(), FragmentDiaryWeight.weightDiaryList.get(i).getmMonth() )); } } dp = new DataPoint[i]; for (i = 0; i < weightDiaryListSorted.size(); i++) { dp[i] = new DataPoint(weightDiaryListSorted.get(i).getmDay(), weightDiaryListSorted.get(i).getmWeight()); } LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dp); On the LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dp); line LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dp); crashes to null due to:
java.lang.NullPointerException: Attempt to invoke interface 'double com.jjoe64.graphview.series.DataPointInterface.getX ()' on a null object reference
I do not understand why, because dp contains positions with x and y coordinates.
How to fix?