title: Android - Bitmap from URL added to rootview
body: <p>I'm having a bit of trouble pulling a bitmap from a url. I used an example from another question here on Stack, but it will not load the image. Here is the code: </p>
  
  <pre><code>public class Image extends Activity{
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Bitmap bitmap = DownloadImage("http://cogadget.com/cogadget/wp-content/uploads/2010/05/Android-Logo-50x50.jpg");
      ImageView img = (ImageView) findViewById(R.id.imageView1);
      img.setImageBitmap(bitmap);
  }
  
  private InputStream OpenHttpConnection(String urlString) throws IOException {
      InputStream in = null;
      int response = -1;
  
      URL url = new URL(urlString);
      URLConnection conn = url.openConnection();
  
      if (!(conn instanceof HttpURLConnection))
          throw new IOException("Not an HTTP connection");
  
  
      try {
          HttpURLConnection httpConn = (HttpURLConnection) conn;
          httpConn.setAllowUserInteraction(false);
          httpConn.setInstanceFollowRedirects(true);
          httpConn.setRequestMethod("GET");
          httpConn.connect();
          response = httpConn.getResponseCode();
          if (response == HttpURLConnection.HTTP_OK) {
              in = httpConn.getInputStream();
          }
      } catch (Exception ex) {
          throw new IOException("Error connecting");
  
      }
      return in;
  }
  
  private Bitmap DownloadImage(String URL) {
      Bitmap bitmap = null;
      InputStream in = null;
  
      try {
          in = OpenHttpConnection(URL);
          bitmap = BitmapFactory.decodeStream(in);
          in.close();
      } catch (IOException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
      return bitmap;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm attempting to populate an ImageView with a bitmap from url. I can connect to the internet on my emulator, but in the logcat it tells me it can't establish a connection. I also set permissions in the manifest for the internet. I'm dumbfounded by what is probably an easy fix.</p>