title: Why the null pointer exception? Camera application
body: <p>Im getting the following crash report</p>
  
  <p><code>Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/3322 (has extras) }} to activity {com.example.instareport/com.example.instareport.MainActivity}: java.lang.NullPointerException</code></p>
  
  <p>My fragment_main.xml looks like this</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.instareport.MainActivity$PlaceholderFragment" &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" /&gt;
  
      &lt;ImageView 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:visibility="visible"
          android:id="@+id/imageView1" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and my MainActivity class is below</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      static final int REQUEST_IMAGE_CAPTURE = 1;
      private ImageView mImageView;
      private Bitmap  imageBitmap;
  
      private void dispatchTakePictureIntent() {
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
              startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
          }
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
              super.onActivityResult(requestCode, resultCode, data);
              Bundle extras = data.getExtras();
              imageBitmap = (Bitmap) extras.get("data");
              mImageView.setImageBitmap(imageBitmap);
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mImageView = (ImageView)findViewById(R.id.imageView1);
          if (savedInstanceState == null) {
              getFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment()).commit();
          }
          dispatchTakePictureIntent();
      }
  
      @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;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      /**
       * A placeholder fragment containing a simple view.
       */
      public static class PlaceholderFragment extends Fragment {
  
          public PlaceholderFragment() {
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_main, container,
                      false);
              return rootView;
          }
      }
  
  }
  </code></pre>
  
  <p>Basically, whent the app launches, it should call the Camera App since there is an intent delievered to it,, and when I press the shutter button, I press Ok (to accept the image), and then it starts to crash. </p>
  
  <p>I tried inserting breakpoint at the following line,, and this is where the code throws an exception</p>
  
  <pre><code>mImageView.setImageBitmap(imageBitmap);
  </code></pre>
  
  <p>Why is that so? I tried to follow the Android tutorials from both the official Android website and Android tutorial's point.</p>
  
  <p>Thanks</p>
  
  <p>edited.</p>
  
  <p>here is the logcat</p>
  
  <pre><code>07-17 21:16:12.131: W/dalvikvm(21693): threadid=1: thread exiting with uncaught exception (group=0x41522438)
  07-17 21:16:12.191: E/AndroidRuntime(21693): FATAL EXCEPTION: main
  07-17 21:16:12.191: E/AndroidRuntime(21693): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/3322 (has extras) }} to activity {com.example.instareport/com.example.instareport.MainActivity}: java.lang.NullPointerException
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3248)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.ActivityThread.access$1100(ActivityThread.java:138)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1252)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.os.Handler.dispatchMessage(Handler.java:99)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.os.Looper.loop(Looper.java:137)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.ActivityThread.main(ActivityThread.java:4911)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at java.lang.reflect.Method.invoke(Method.java:511)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at dalvik.system.NativeStart.main(Native Method)
  07-17 21:16:12.191: E/AndroidRuntime(21693): Caused by: java.lang.NullPointerException
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at com.example.instareport.MainActivity.onActivityResult(MainActivity.java:66)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.Activity.dispatchActivityResult(Activity.java:5492)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
  07-17 21:16:12.191: E/AndroidRuntime(21693):    ... 11 more
  </code></pre>