Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android致命异常:Can';t在未调用Looper.prepare()的线程内创建处理程序_Android_Multithreading_Handler - Fatal编程技术网

Android致命异常:Can';t在未调用Looper.prepare()的线程内创建处理程序

Android致命异常:Can';t在未调用Looper.prepare()的线程内创建处理程序,android,multithreading,handler,Android,Multithreading,Handler,我读过关于这个问题的类似问题,并试图找到解决办法,但我还没有弄清楚我的情况是什么原因。我的程序代码如下: public class ReportSystem extends Activity implements SensorEventListener , Runnable{ ReportLocation reportObj = new ReportLocation(this); //my other class Thread thread_send = new Thread

我读过关于这个问题的类似问题,并试图找到解决办法,但我还没有弄清楚我的情况是什么原因。我的程序代码如下:

public class ReportSystem extends Activity implements SensorEventListener , Runnable{ 

    ReportLocation reportObj = new ReportLocation(this); //my other class
    Thread thread_send = new Thread(this);

    Handler handler = new Handler() {
        public void handleMessage(Message message) {    
            msg.setText("---"));
        }
    };

    public void onCreate(Bundle savedInstanceState){ 
    //something...
    }

    public void onSensorChanged(SensorEvent event){ 

        if(event.values[0] > 10)
            thread_send.start(); // thread is started..
    }

    public void run(){

        reportObj.send(); //connect with server and send data by the help of RepotLocation class' send function
        handler.sendEmptyMessage(0);
    }
}//end class
我应该怎么做才能解决这个问题?

试试这个:

public void run(){
    Looper.prepare();
    reportObj.send();
    handler.sendEmptyMessage(0);
    Looper.loop();
}
试试这个:

public void run(){
    Looper.prepare();
    reportObj.send();
    handler.sendEmptyMessage(0);
    Looper.loop();
}