0

When I run the application with eclipse it shows me an error: "can't create handler inside thread that hos not called looper.prepare()" and I do not understanding why.

This is a part of my code

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

   }
};
Marko
  • 20,385
  • 13
  • 48
  • 64

1 Answers1

1

You will get this error, with the above code, if the code that is creating an instance of this class is running on a thread other than the main application thread.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • This code works when there is informations to display in the list, but if the function get_liste_arrives() does not return any rows from the data base,the application stops when I click the button which leads me to the class of this code. – Amigo Mogo Sep 26 '12 at 11:12