2012-09-25 41 views
0

当我用eclipse运行应用程序时,它向我显示一个错误:"can't create handler inside thread that hos not called looper.prepare()",我不理解为什么。不能在线程内创建处理程序,该线程不会调用looper.prepare()?

这是我的代码的一部分

public void execute_web_service() { 
    progressd = ProgressDialog.show(liste_voyage.this, "", "Chargement...", true, 
      false); 

    Thread thread = new Thread(liste_voyage.this); 
    thread.start(); 

} 




public void run() { 


    get_liste_arrives(); 

    handler.sendEmptyMessage(0); 
} 



private Handler handler = new Handler() { 
    @Override 
    public void handleMessage(Message msg) { 
     progressd.dismiss(); 
     afficher_liste_arrives(); 

    } 
}; 
+0

你可能会发现这个答案有帮助: http://stackoverflow.com/a/6213637/1686442 –

回答

1

你会得到这个错误,与上面的代码,如果是创建该类的实例的代码在除主应用程序的线程上运行线。

+0

此代码工作时有信息显示在列表中,但如果函数get_liste_arrives()不返回任何来自数据库的行,应用程序停止时,我点击按钮,这导致我的代码类。 –

相关问题