title: How to place image at Layout by java? Android
body: <p>I have an image called c1.png in drawable-mdpi folder. I want to put it to layout by Java with this:</p>
  
  <pre><code>package ...;
  
  import android.os.Bundle;
  //import android.provider.MediaStore.Images;
  import android.app.ActionBar.LayoutParams;
  import android.app.Activity;
  import android.view.Menu;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  
  public class MainActivity extends Activity 
  {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          LinearLayout layout = (LinearLayout)findViewById(getCurrentFocus().getId() );
  
          ImageView img = new ImageView(this);
          ViewGroup.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          img.setLayoutParams(lp);
          img.setImageDrawable(getResources().getDrawable(R.drawable.c1));
          layout.addView(img);
          setContentView(layout);//Doesn't matter, if it's commented or not. The error still exists.
      }
      @Override
      public boolean onCreateOptionsMenu(Menu menu) 
      {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  
  }
  </code></pre>
  
  <p>I got: "Unfortunately, %application_name has stopped" when launched it. I saw many examples, using R.id.* in id params, but it stopped too (like R.id.linearLayout1), or R had not such constansts (like R.id.c1).
  How can I do this?</p>