GraphView - graphviewseries null

时间:2014-11-13 16:07:20

标签: android arrays graph android-graphview

我的grapviewseries似乎总是为null,即使我的graphhviewdata中有值

这是我的代码:

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);

这些是给我的错误:

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 个答案:

答案 0 :(得分:0)

您正在创建一个包含1000个元素的数组

GraphViewData []graphViewData = new GraphViewData[1000] ;

但您只需为第一个listprice.size()元素设置值。其余的都是空的。

使数组只有listprice.size()个元素,或者将当前的空值设置为某个适当的非空值,例如GraphViewData(0.0,0.0)