title: Updating TextView from Async Task which use custom program dialog
body: <p>In one of my app, I have a scenario where I need to do some background task. For doing that I am using Async Task. Also I am using custom progress dialog. Below is the layout of the custom progress dialog </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/layout_root"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center_vertical|center_horizontal"
      android:orientation="vertical" &gt;
  
      &lt;ProgressBar
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:indeterminateDrawable="@drawable/progressloader" 
          android:layout_gravity="center"/&gt;
  
      &lt;TextView
          android:id="@+id/progressMessage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="@color/black"
          android:textSize="18sp"
          android:text="Please wait...." /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Everything works fine but when I try to set text to TextView then I am getting java NullPointerException. </p>
  
  <p>AsyncTask code </p>
  
  <pre><code>private class InitialSetup extends AsyncTask&lt;String, Integer, Long&gt; {
  
          ProgressDialog dialog = new ProgressDialog(getParent(),R.style.progressdialog);
  
  
          @Override
          protected void onPreExecute() {
              dialog.show();
              dialog.setContentView(R.layout.progressbar);
  
          }
  
          @Override
          protected Long doInBackground(String... urls) {
                      //    txtView.setText("Testing");    here I am getting the error
              fetchDetails();
  
              return 0;
          }
  
          @Override
          protected void onPostExecute(Long result) {
  
              if (this.dialog.isShowing()) {
                  this.dialog.dismiss();
              }
  
              populateUI(getApplicationContext());
          }
      }
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>public class SummaryActivity extends Activity {
  
  
  final TextView txtView = (TextView)findbyid(R.id.progressMessage);
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.accountsummary);
  
                new InitialSetup().execute("");
  
      }
  }
  </code></pre>