title: Unable to Update the progress bar inside and alert dialog builder
body: <p>I am trying to create a progress bar inside a alert dialog builder and trying to update the progress when i click on button using threads and handlers .....but every time i click on the start button it crashes ....</p>
  
  <pre><code>package com.example.progressbar_thread;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.os.Bundle;
  import android.os.Handler;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.ProgressBar;
  
  public class MainActivity extends Activity implements OnClickListener {
  
  Button Start;
  int i = 0;
  Handler myHandler = new Handler();
  ProgressBar myProgressBar;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Start = (Button) findViewById(R.id.StartButton);
      Start.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
      // TODO Auto-generated method stub
      // Alert dialog builder section 
      AlertDialog.Builder myDialogBuilder = new AlertDialog.Builder(this);
      myDialogBuilder.setTitle("Progress...");
      View ProgressView = getLayoutInflater().inflate(R.layout.progressbar,
              null);
      myProgressBar=(ProgressBar)findViewById(R.id.ProgressBar);   
  
      myDialogBuilder.setView(ProgressView);
      myDialogBuilder.create().show();
  
      new Thread(new Runnable() {
  
          @Override
          public void run() {
  
              // TODO Auto-generated method stub
              while (i &lt; myProgressBar.getMax()) {
  
                  myHandler.post(new Runnable() {
  
                      @Override
                      public void run() {
                          // TODO Auto-generated method stub
                          myProgressBar.setProgress(i);   //Updading progress 
  
                      }
  
                  });
  
                  i++;
  
              }
  
          }
      }).start();
  
      }
  
      }enter code here
  </code></pre>