Android null object reference on ProgressBar in dialog
<p>I have the following code where I create a ProgressBar in a dialog:</p>

<pre><code>final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.wait_for_response_dialog);

final ProgressBar bar = (ProgressBar) findViewById(R.id.responseWaitBar);
final int[] i = {0};

bar.setProgress(i[0]);
</code></pre>

<p>And my layout of the ProressBar is the following in <code>wait_for_response_dialog.xml</code>:</p>

<pre><code>&lt;ProgressBar
        android:id="@+id/responseWaitBar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" /&gt;
</code></pre>

<p>But I get the following error for line <code>bar.setProgress(i[0]);</code>:</p>

<p><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setProgress(int)' on a null object reference</code></p>