【问题标题】:GraphView - graphviewseries nullGraphView - graphviewseries null
【发布时间】:2014-11-13 16:07:20
【问题描述】:

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

这是我的代码:

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)

【问题讨论】:

    标签: android arrays graph android-graphview


    【解决方案1】:

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

    GraphViewData []graphViewData = new GraphViewData[1000] ;
    

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

    要么让你的数组只有listprice.size() 元素,要么将当前的空值设置为一些适当的非空值,例如GraphViewData(0.0,0.0)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多