GraphView从数组读取数据点导致应用程序冻结

时间:2019-03-03 22:11:22

标签: java arrays arraylist android-graphview

我正在尝试使用Android应用程序上的GraphView库显示图形(日期作为X标签)。当我尝试该库时,我伪造了一组数据点,并且工作正常。但是,当我尝试使用传递给函数的自己的数据时,即使我将数组的大小定为final,并且所有值在调试器中看起来都是正确且有效的,logcat仍然告诉我

Background sticky concurrent mark sweep GC freed 662839(10MB) AllocSpace objects

,该应用程序冻结。我的数据数组的大小仅为4,甚至比我使用的假数据还小,所以我真的很想知道这个问题是从哪里来的。

以下是显示图表的功能:

private void displayGraph(ArrayList<String> graphData) throws ParseException {
        final int numDate = graphData.size() / 2;
        DataPoint[] allDataPoints = new DataPoint[numDate];
        ArrayList<Date> allDates = new ArrayList<Date>(numDate);
        ArrayList<Integer> allData = new ArrayList<Integer>(numDate);
        ArrayList<Date> noDates = new ArrayList<Date>();
        ArrayList<Integer> noData = new ArrayList<Integer>();
        int numNoDates = 0;

        SimpleDateFormat formatter = new SimpleDateFormat("MMM DD, yyyy");

        // parse the dates and distinguish those "didn't"
        for (int i = 0; i < numDate; i++) {
            String sDate = graphData.get(i * 2);
            Date date = formatter.parse(sDate);
            allDates.add(date);

            String sdata = graphData.get(i * 2 + 1);
            String[] data = sdata.split(" ");
            allData.add(Integer.parseInt(data[2]));

            allDataPoints[i] = new DataPoint(date, Integer.parseInt(data[2]));

            if (!data[3].equals("did")) {
                noDates.add(date);
                noData.add(Integer.parseInt(data[2]));
                numNoDates++;
            }
        }

        DataPoint[] noDataPoints = new DataPoint[numNoDates];
        for (int i = 0; i < numNoDates; i++) {
            noDataPoints[i] = new DataPoint(noDates.get(i), noData.get(i));
        }

        LineGraphSeries<DataPoint> line = new LineGraphSeries<DataPoint>(allDataPoints);
        line.setColor(Color.WHITE);
        graph.addSeries(line);

    }

这里不包括图形的样式(我很确定它们可以正常工作,并且程序在到达那里之前就冻结了)。我尝试了很多方法来解决它,并使用各种数据结构来保留数据,但是即使从该系列构造函数中的数据ArrayLists手动创建> 1个DataPoints也会导致相同的问题。

如果有人知道问题可能在哪里,以及我如何解决该问题,我将不胜感激! 谢谢!

0 个答案:

没有答案