title: Android AsyncTask Can't create handler inside thread that has not called Looper.prepare()?
body: <p>Why i am getting this error when i use this code in the <code>asynctask</code> even i am using  <code>runOnUiThread()</code> this is the code i am using ( i am using fragments ).</p>
  
  <pre><code>private class GmailXMPP_AfterLogin extends AsyncTask&lt;AfterLogging, Void, Void&gt; {
  
      private ProgressDialog _dialog;
  
      @Override
      protected void onPreExecute() {          
          super.onPreExecute();
          _dialog = new ProgressDialog(getActivity());     
          _dialog.setCancelable(false);
          _dialog.setTitle("colors");
          //((ProgressDialog)dialog).setIcon(R.drawable.icon);
          _dialog.setMessage("Your content is loading.. \nPlease wait..");
          _dialog.setIndeterminate(false);         
          _dialog.show();
          //ProgressBar_show();
          Log.i(TAG, " GmailXMPP_AfterLogin onPreExecute" );
      }
  
      @Override
      protected void onPostExecute(Void feed) {
          //ProgressBar_hide();       
          _dialog.dismiss();
          Log.i(TAG, " GmailXMPP_AfterLogin onPostExecute" );
      }
  
      @Override
      protected Void doInBackground(AfterLogging... arg0) {
  
          Log.i(TAG, " GmailXMPP_AfterLogin doInBackground" );
          AfterLogging after = arg0[0];
          final XMPPConnection _connection = after.getConn();
          final String Uname = after.getAcc_Name();
  
                  //synchronized (contactJids) {
          Roster roster = Gtalk_xmpp_client.getRoster();
          String file_name;
          for (RosterEntry entry : roster.getEntries()) {
              if (entry.getType() == ItemType.to || entry.getType() == ItemType.both) {
  
                  boolean yes = Contact_data_source.checkUsername(entry.getUser());
                  Log.i(TAG, "Con=" + yes);
                  if (!yes) {
  
                      Bitmap buddy_img = buddyImage(entry, _connection);
                      if (buddy_img != null)
                          file_name = Store(buddy_img);
                      else
                          file_name = "";
                      if (entry.getName() == null)
                          Contact_data_source.createContact( entry.getUser(), entry.getUser(), Uname, file_name, UsedStrings.GoogleAccount );
                      else
                          Contact_data_source.createContact( entry.getName(), entry.getUser(), Uname, file_name, UsedStrings.GoogleAccount );
                  } else {
                      Log.i(TAG, "Con=exist");
                  }
              }
          }               
          return null;
      }
   }
  </code></pre>
  
  <p>logcat shows </p>
  
  <pre><code>12-01 11:59:21.549: E/AndroidRuntime(16595): FATAL EXCEPTION: AsyncTask #1
  12-01 11:59:21.549: E/AndroidRuntime(16595): java.lang.RuntimeException: An error occured while executing doInBackground()
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.lang.Thread.run(Thread.java:1019)
  12-01 11:59:21.549: E/AndroidRuntime(16595): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.os.Handler.&lt;init&gt;(Handler.java:121)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.app.Dialog.&lt;init&gt;(Dialog.java:101)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:63)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:80)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:76)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at com.pipemedia.fragments.ChatAccountsFragment$GmailXMPP_AfterLogin.onPreExecute(ChatAccountsFragment.java:372)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.os.AsyncTask.execute(AsyncTask.java:391)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at com.pipemedia.fragments.ChatAccountsFragment.Gtalk_logInComplete(ChatAccountsFragment.java:435)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at com.pipemedia.xmpp.GmailXmppClient.Login(GmailXmppClient.java:60)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at com.pipemedia.fragments.ChatAccountsFragment$GmailXMPP.doInBackground(ChatAccountsFragment.java:337)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at  com.pipemedia.fragments.ChatAccountsFragment$GmailXMPP.doInBackground(ChatAccountsFragment.java:1)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  12-01 11:59:21.549: E/AndroidRuntime(16595):    ... 4 more
  </code></pre>
  
  <p>this is the line creating error </p>
  
  <pre><code>line 372 : progress_dialog = new ProgressDialog(getActivity());
  </code></pre>