title: Why I can't show image inside custom dialog?
body: <p>I want to create some sort of logging procedure in my Android app.
  I have managed to detect where user is pressing on the screen (three times) and to create logging sequence from that.
  On the end, I want to show 3 images which represent selected logging sequence (from my drawable folder)</p>
  
  <p>I have dynamically set drawable ID and it works when I place image on main layout.
  But if I place image inside custom dialog, I get force close.
  From LogCat I see following: <strong>java.lang.NullPointerException</strong> at       <code>image1.setImageResource(iIdSlike);</code></p>
  
  <p>If I show drawable ID as a text it's OK and ID is the same on main and custom dialog layout.</p>
  
  <p>I get force close even if I set image like this (not dynamically):    </p>
  
  <pre><code> image1.setImageResource(R.drawable.s11);
  </code></pre>
  
  <p>Why I can't show image on custom dialog?</p>
  
  <p>This is my dijalog.xml (custom dialog layout):</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"&gt;
  
       &lt;ImageView
           android:id="@+id/imgDrugi"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignRight="@+id/TextView01"
           android:layout_below="@+id/TextView01"
           android:layout_marginRight="27dp"
           android:layout_marginTop="51dp"
            /&gt;
  
       &lt;Button
           android:id="@+id/button1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_alignParentRight="true"
           android:text="Button" /&gt;
  
       &lt;TextView
           android:id="@+id/TextView01"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentTop="true"
           android:layout_centerHorizontal="true"
           android:layout_marginTop="118dp"
           android:text="@+id/TextView01" /&gt;
  
      &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And this is my code:</p>
  
  <pre><code>public class MyWorkLogiranje extends Activity implements OnClickListener
  {
      @Override
      public boolean onTouchEvent(MotionEvent event) 
      {
          switch(event.getAction())
          {
            case MotionEvent.ACTION_DOWN:                 
                  .
                  .
                  .               
                        //calculations to get string sPrvi
  
  
                     sPrvi="s31"; //For testing purposes sPrvi set manually          
  
                     //Image and text on main layout (it works)
                     iIdSlike = getResources().getIdentifier(sPrvi, "drawable", getPackageName());
                     ImageView image = (ImageView) findViewById(R.id.imgPrvi);
                     image.setImageResource(iIdSlike);
  
                     TextView text1 = (TextView)findViewById(R.id.txtPrvi);
                     text1.setText("iIdSlike: " + iIdSlike);
  
                     //Prikaz dijaloga
  
                     final Dialog dialog = new Dialog(MyWorkLogiranje.this);
                     dialog.setContentView(R.layout.dijalog);
                     dialog.setTitle("This is my custom dialog box");
                     dialog.setCancelable(true);
                     dialog.getContext();
  
                     TextView text = (TextView) dialog.findViewById(R.id.TextView01);
                     text.setText("iIdSlike: " + iIdSlike);
                     ImageView image1 = (ImageView) findViewById(R.id.imgDrugi);
                     image1.setImageResource(R.drawable.iIdSlike);
                     //image1.setImageResource(R.drawable.s11);
  
                     //Podešavanje dugmeta
                     Button button = (Button) dialog.findViewById(R.id.button1);
                     button.setOnClickListener(new OnClickListener() 
                     {
                         @Override
                          public void onClick(View v) 
                          {
                             dialog.dismiss();
                          }
                      });   
                     dialog.show();
  </code></pre>
  
  <p>Can anyone help me with this please?
  I'm scratching my head for two days about this.
  Thank you.</p>