title: android:Can't create handler inside thread that has not called Looper.prepare()
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3614663/cant-create-handler-inside-thread-that-has-not-called-looper-prepare-inside-a">Can’t create handler inside thread that has not called Looper.prepare() inside AsyncTask for ProgressDialog</a>  </p>
  </blockquote>
  
  
  
  <p>In my program I want show progress-dialog, for that I have created thread, but it gives me<code>Can't create handler inside thread that has not called Looper.prepare()</code> I look previous posted question also but I can handle this . this is my code</p>
  
  <pre><code>        dialog=ProgressDialog.show(Login.this, "Connecting to the Server", "Please wait");
  
          Thread thred=new Thread(new Runnable() {
  
              public void run() {
                    try {
  
  
                        // Create a new HttpClient and Post Header
                          HttpClient httpclient = new DefaultHttpClient();           
                          HttpPost httppost = new HttpPost("http://www.diskonbanget.com/bni/login/login.php");
                          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
                          nameValuePairs.add(new BasicNameValuePair("username", username));
                          nameValuePairs.add(new BasicNameValuePair("password", password));
                          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
                          // Execute HTTP Post Request
  
                          HttpResponse response = httpclient.execute(httppost);
  
                          String str = inputStreamToString(response.getEntity().getContent()).toString();
  
  
                          if(str.toString().equalsIgnoreCase("false"))
                          {
                              dialog.dismiss();
                              AlertDialog alert = new AlertDialog.Builder(Login.this).create();                       
                              alert.setMessage("Please enter valid username &amp; Password");
                              alert.setButton("OK",new DialogInterface.OnClickListener() {
                                          public void onClick(DialogInterface dialog,int which) {
                                          }
                                      });
  
                            alert.setIcon(R.drawable.loginlogo); 
                            alert.show();
  
  
                          }
                          else{   
  
                               Intent intent=new Intent(Login.this,MainMenu.class);
                               intent.putExtra("photo", str);
                               intent.putExtra("username", username);
                               txtusername.setText("");
                               txtPassword.setText("");
                               dialog.dismiss();
                               startActivity(intent);
  
  
                          }
  
                      } catch (Exception e) {
                          dialog.dismiss();
                          AlertDialog alert = new AlertDialog.Builder(Login.this).create();                       
                          alert.setMessage("Can not Connect to the server.please make sure your internet is Switch on");
                          alert.setButton("OK",new DialogInterface.OnClickListener() {
                                      public void onClick(DialogInterface dialog,int which) {
                                      }
                                  });
                          alert.setIcon(R.drawable.loginlogo); 
  
                          alert.show();
                      } 
  
  
              }
          });
          thred.start();
  </code></pre>
  
  <p>please someone help me to fix this problem.</p>