GraphView - graphviewseries null

819 views Asked by At

my grapviewseries seems to be always null even though i have values inside my graphhviewdata

This is my code here :

GraphViewData []graphViewData = new GraphViewData[1000] ;
        for (int i = 0; i < listprice.size(); i++) {
            Log.e("date", String.valueOf(listdate.get(i)));
            Log.e("price",String.valueOf( listprice.get(i)));
            graphViewData[i] = new GraphViewData(listdate.get(i), listprice.get(i));

        }

        GraphViewSeries exampleSeries = new GraphViewSeries( graphViewData);


        GraphView graphView = new LineGraphView(getActivity() // context
                , "" // heading
        );
        ((LineGraphView) graphView).setDrawDataPoints(true);
        ((LineGraphView) graphView).setDataPointsRadius(15f);
        graphView.addSeries(exampleSeries); // data

        LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.layout);
        layout.addView(graphView);

These are the errors that are given to me :

11-14 00:02:10.559: E/AndroidRuntime(14809): java.lang.NullPointerException
11-14 00:02:10.559: E/AndroidRuntime(14809): at com.jjoe64.graphview.GraphViewSeries.checkValueOrder(GraphViewSeries.java:199)
11-14 00:02:10.559: E/AndroidRuntime(14809):    at com.jjoe64.graphview.GraphViewSeries.<init>(GraphViewSeries.java:91)
1

There are 1 answers

0
th65 On

You're creating an array of 1000 elements

GraphViewData []graphViewData = new GraphViewData[1000] ;

but you're only setting values for the first listprice.size() elements. The rest are null.

Either make your array have only listprice.size() elements, or set the currently null values to some appropriate non-null value such as GraphViewData(0.0,0.0).