Java 在Android中对LineGraphView对象使用addPoint()方法时出现StackOverflowerError

Java 在Android中对LineGraphView对象使用addPoint()方法时出现StackOverflowerError,java,android,arraylist,stack-overflow,linegraph,Java,Android,Arraylist,Stack Overflow,Linegraph,调用太多方法而未返回时,会出现StackOverflowerError。在这种情况下,addPoint()。当一个方法调用自身时,它被称为递归。我不知道addPoint()。如果递归是有意的,那么问题在于您没有创建一个确定递归何时停止的基本情况。为什么要使用没有基本情况的递归?更重要的是,你为什么要使用递归?我没有使用递归,你说的是代码的哪一部分?递归是当一个方法调用自己时。addPoint()的最后一行是对addPoint()的调用。这就是导致堆栈溢出错误的原因。我没有编写addPoint()

调用太多方法而未返回时,会出现
StackOverflowerError
。在这种情况下,
addPoint()。当一个方法调用自身时,它被称为递归。我不知道
addPoint()。如果递归是有意的,那么问题在于您没有创建一个确定递归何时停止的基本情况。

为什么要使用没有基本情况的递归?更重要的是,你为什么要使用递归?我没有使用递归,你说的是代码的哪一部分?递归是当一个方法调用自己时。
addPoint()
的最后一行是对
addPoint()
的调用。这就是导致堆栈溢出错误的原因。我没有编写addPoint()方法,它是Android的
LineGraphView
库的一部分。当参数为
event.values
而不是我创建的
List
对象时,它在没有StackOverflower错误的情况下工作。@tnecniv
LineGraphView
不是标准的Android类。你从哪里得到的?我想是从这里:我应该停止使用ListGraphView对象吗?有没有标准的Android库可以用来显示加速器数据的图形?请看,您的编辑很清楚,在第一个addPoint()函数中,您需要使用addPoint(floats)而不是addPoint(y)来完成;
// Initializing the LineGraphView object and adding it to linLayout 
        graph = new LineGraphView(rootView.getContext(), 100, Arrays.asList("x", "y", "z"));
        linLayout.addView(graph);
        graph.setVisibility(View.VISIBLE);


@Override
    public void onSensorChanged(SensorEvent event) {
        if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        {
            // Obtaining accelerometer values
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];

            float pythagorean = (float)Math.sqrt(x*x + y*y + z*z);

            List<Float> graph_points = new ArrayList<Float>();
            graph_points.add(pythagorean);

            output.setText("\npythagorean\n"
                    + "pythagorean: " + String.valueOf(pythagorean));

            // Adding the current accelerometer values to the LinearGraphView object
            graph.addPoint(graph_points); 

        }
    }
// LineGraphView.java --> From LineGraphView Lib, I didn't write this!
/**
 * Adds a set of datapoints for the next x value. The data points should be in the same 
 * order as the array of labels this object was initialized with.
 * @param y The List of datapoints.
 */

public void addPoint(float[] y)
{
    points.add(y.clone());
    if(points.size() > maxDataWidth)
        points.remove(0);

    invalidate();
}

public void addPoint(List<Float> y)
{
    float[] floats = new float[y.size()];

    for(int i = 0; i < y.size(); i++){
        floats[i] = y.get(i);
    }
    addPoint(y);
}