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();
}