title: Android - Set ImageView to URL
body: <p>I am trying to set an Imageview to a URL.</p>
  
  <p>Below is my code</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.getpic);
      ImageView i = (ImageView)findViewById(R.id.ivget);
  
      URL url;
      try {
  
          url = new URL("http://0-media-cdn.foolz.us/ffuuka/board/sp/thumb/1359/41/1359419073599s.jpg");
          Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
          i.setImageBitmap(image);
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>But whenever I try to open/run the app it crashes, why isnt it working?</p>
  
  <pre><code>06-15 00:37:20.977: E/AndroidRuntime(8579): FATAL EXCEPTION: main
  06-15 00:37:20.977: E/AndroidRuntime(8579): java.lang.RuntimeException: Unable to  instantiate activity  ComponentInfo{com.OptimusApps.stayhealthy/com.OptimusApps.stayhealthy.Practice2}:  java.lang.NullPointerException
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993)
   06-15 00:37:20.977: E/AndroidRuntime(8579):    at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.app.ActivityThread.access$600(ActivityThread.java:132)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.os.Handler.dispatchMessage(Handler.java:99)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.os.Looper.loop(Looper.java:137)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.app.ActivityThread.main(ActivityThread.java:4575)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at java.lang.reflect.Method.invokeNative(Native Method)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at  java.lang.reflect.Method.invoke(Method.java:511)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at dalvik.system.NativeStart.main(Native Method)
  06-15 00:37:20.977: E/AndroidRuntime(8579): Caused by: java.lang.NullPointerException
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.app.Activity.findViewById(Activity.java:1794)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at com.OptimusApps.stayhealthy.Practice2.&lt;init&gt;(Practice2.java:17)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at java.lang.Class.newInstanceImpl(Native Method)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at java.lang.Class.newInstance(Class.java:1319)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984)
  06-15 00:37:20.977: E/AndroidRuntime(8579):     ... 11 more
  </code></pre>
  
  <p>above is the logcat, I am not sure where the error is in it specificaly though..............................................................................................................................................................</p>