title: DialogFragment: always a Null Pointer Exception using a progress bar. How to solve it?
body: <p>Consider this DialogFragment:</p>
  
  <pre><code>public class RollTriggerDialog extends DialogFragment{
  
      private ProgressDialog _dialog;
      int _progress;
      public Handler _progressHandler;
  
      public RollTriggerDialog() {
          // empty
      }
  
      @Override
      public Dialog onCreateDialog(final Bundle savedInstanceState) {
          _dialog = new ProgressDialog(getActivity());
  
          this.setStyle(STYLE_NO_TITLE, getTheme());
          _dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
          _dialog.setProgress(0);
  
          _progressHandler = new Handler() {
              public void handleMessage(Message msg) {
                  super.handleMessage(msg);
  
                  if (_progress &gt;= 100) {
                      _dialog.dismiss();
                  } else {
                      _progress++;
                      _dialog.incrementProgressBy(1);
                      _progressHandler.sendEmptyMessageDelayed(0,100);
                  }
  
              }
          };
          //_progressHandler.sendEmptyMessage(0); &lt;- This uncommented would start the progress
          return _dialog;
      }
  }
  </code></pre>
  
  <p>It is just a horizontal progressbar with a handler, once the handler receives one message the progressbar goes from 0 to 100.</p>
  
  <p>I am always <strong>getting a Null Pointer Exception</strong> if I want to trigger that sendEmptyMessage by myself from an activity:</p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
  
      private RollTriggerDialog mRollTriggerDialog;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          FragmentManager fm = getSupportFragmentManager();
          mRollTriggerDialog = new RollTriggerDialog();
          mRollTriggerDialog.show(fm, "addDiceDialog_tag");
          ((RollTriggerDialog)fm.findFragmentByTag("addDiceDialog_tag"))._progressHandler.sendEmptyMessage(0); // &lt;--- NPE HERE!
      }
  }
  </code></pre>
  
  <p>If the line of sendEmptyMessage is uncommented in the dialogFragment and the line with NPE in the main activity is commented; the app runs. What is wrong with that invocation?</p>
  
  <p>Note that this is the whole code, excepting manifest and layout files.  </p>