Android应用程序中的FATAL EXCEPTION错误

时间:2016-04-02 07:38:05

标签: java android multithreading

我在StackOverflow中看到了很多FATAL EXCEPTION问题。但是不同的人有不同的问题。所以我想讨论我的问题是否可以有线索。

我有AcceInterface ClassRawData ClassAcceInterface Class读取加速度计数据并放入三个队列(queuex,queuey,queuez)。然后RawData Class在Runnable THread中读取这些队列并使用AChartEngine显示。

这是AcceInterface Class

public class AcceInterface implements SensorEventListener {
    private SensorManager sensorManager;
    private Sensor accelerometer;
    public Queue<Float> queuex;
    public Queue<Float> queuey;
    public Queue<Float> queuez;
    //Filter
    IIRDirectForm2Transposed filt = new IIRDirectForm2Transposed();   


    public void createSensorContext(Context context){
        sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
            // success! we have an accelerometer
            accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
            sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
            // vibrateThreshold = accelerometer.getMaximumRange() / 2;
        } else {
            // fai! we dont have an accelerometer!
        }

        queuex = new ConcurrentLinkedQueue<Float>();
        queuey = new ConcurrentLinkedQueue<Float>();
        queuez = new ConcurrentLinkedQueue<Float>();
        //Initialize filter
        filt.initialization();


    }

    public void deleteSensor(){
        sensorManager.unregisterListener(this);
        queuex.clear();
        queuey.clear();
        queuez.clear();
    }
    @Override
    public void onSensorChanged(SensorEvent event) {    

        //Filter before put into queues
        filt.IIRDirectForm2TransposedFilteration(event.values[0], event.values[1],event.values[2]);
        queuex.add(Float.valueOf(filt.out[0]));
        queuey.add(Float.valueOf(filt.out[1]));
        queuez.add(Float.valueOf(filt.out[2]));


    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }
}

然后Runnable类如下。

acce = new AcceInterface();
class Plot implements Runnable
{

        Thread mythread ;
        Plot()
        {
            mythread = new Thread(this, "my runnable thread");
            System.out.println("my thread created" + mythread);
            mythread.start();
        }

        public void run()
        {
            while (systemON) {

                if (!acce.queuex.isEmpty()) {
                    mSeriesX.add(xx_axis++, acce.queuex.poll().floatValue());
                    if (xx_axis % 50 == 0) {
                        mChartView_x.repaint();
                    }
                    if (xx_axis % 3000 == 0) {
                        mRenderer_x.setXAxisMin(xx_axis);
                        mRenderer_x.setXAxisMax(xx_axis + 3000);


                    }
                    //if (mChartView_x != null) {

                    //}


                }
                if (!acce.queuey.isEmpty()) {
                    mSeriesY.add(xy_axis++, acce.queuey.poll().floatValue());
                    if (xy_axis % 50 == 0) {
                        mChartView_y.repaint();
                    }
                    if (xy_axis % 3000 == 0) {
                        mRenderer_y.setXAxisMin(xy_axis);
                        mRenderer_y.setXAxisMax(xy_axis + 3000);
                    }

                    // if (mChartView_y != null) {

                    //}


                }
                if (!acce.queuez.isEmpty()) {
                    mSeriesZ.add(xz_axis++, acce.queuez.poll().floatValue());
                    if (xz_axis % 50 == 0) {
                        mChartView_z.repaint();
                    }
                    if (xz_axis % 3000 == 0) {
                        mRenderer_z.setXAxisMin(xz_axis);
                        mRenderer_z.setXAxisMax(xz_axis + 3000);
                    }

                    // if (mChartView_y != null) {

                    //}


                }
            }

        }
 }

我的问题是程序偶尔崩溃,无法找到原因。 logcat如下。

E/AndroidRuntime: FATAL EXCEPTION: main
java.util.ConcurrentModificationException
at java.util.TreeMap$MapIterator.stepForward(TreeMap.java:883)
at java.util.TreeMap$BoundedMap$BoundedIterator.stepForward(TreeMap.java:1485)
at java.util.TreeMap$BoundedMap$BoundedEntrySet$1.next(TreeMap.java:1513)
at java.util.TreeMap$BoundedMap$BoundedEntrySet$1.next(TreeMap.java:1511)
at org.achartengine.chart.XYChart.draw(XYChart.java:250)
at org.achartengine.GraphicalView.onDraw(GraphicalView.java:166)
at android.view.View.draw(View.java:13767)
at android.view.View.getDisplayList(View.java:12718)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3201)
at android.view.View.getDisplayList(View.java:12654)
at android.view.View.getDisplayList(View.java:12762)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1144)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2301)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2173)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1981)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
at dalvik.system.NativeStart.main(Native Method) 

0 个答案:

没有答案