Pushing accelerometer data into an array

笑着哭i 提交于 2019-12-11 16:24:46

问题


I'm having trouble recording the Z-axis data from the accelerometer in an array.

I think I'm probably failing on some basic java rules, but here's what I'm trying to do:

    private ArrayList<Float[]> z = new ArrayList<Float[]>();
            protected void onCreate(Bundle savedInstanceState) {

                    SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        Sensor accelerometer = manager
                .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
            public void onSensorChanged(SensorEvent event) {


                float x = event.values[0];
                float y = event.values[1];
                z.add(event.values[2]);
}

But whenever I try to add to the arraylist I get:

"The method add(Float[]) in the type ArrayList is not applicable for the arguments (float)"

How can I add the z axis data to an array?


回答1:


Its because your ArrayList of Float[] type.

Replace the following,

 private ArrayList<Float[]> z = new ArrayList<Float[]>();

with

 ArrayList<Float> z = new ArrayList<Float>();


来源:https://stackoverflow.com/questions/18615026/pushing-accelerometer-data-into-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!