title: Android app saving and storing images in gallery?
body: <p>How can I save pictures taken by a camera through my app into my device's gallery?</p>
  
  <p>The problem is that the app currently crashes after taking a picture and can only save a single image in the directory specified. 
  Am i right in assuming the app is crashing because it doesn't know what to do after saving a file? How might i go about rectifying this problem, anything after the return statement is "unreachable code".</p>
  
  <p>The code:</p>
  
  <pre><code>public class Activity_Camera extends Activity implements View.OnClickListener {
  
          public static final int cameraData = 1;
  
          ImageButton ib;
          ImageView iv;
          Intent i;
          Bitmap bmp;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_camera);
                  initialise();
          }
  
          private void initialise() {
                  iv = (ImageView) findViewById(R.id.ivPicReturn);
                  ib = (ImageButton) findViewById(R.id.ibTakePic);
  
                  ib.setOnClickListener(this);
          }
  
          public void onClick(View v) {
                  switch (v.getId()) {
                  case R.id.ibTakePic:
                          i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                          //
                          i.putExtra(MediaStore.EXTRA_OUTPUT, getOutputMediaFileUri());              
                          //
                          startActivityForResult(i, cameraData);
                          break;
                  }
          }
          //
          private Uri getOutputMediaFileUri() {
              File imagesFolder = new File(Environment.getExternalStorageDirectory(), "DCIM/TradeIt");
              imagesFolder.mkdirs();  
              File image = new File(imagesFolder, "image.jpg");
              Uri uriSavedImage = Uri.fromFile(image);
              return uriSavedImage;
  
  
          }
          //
          @Override
          protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                  super.onActivityResult(requestCode, resultCode, data);
                  if (resultCode == RESULT_OK) {
                          Bundle extras = data.getExtras();
                          bmp = (Bitmap) extras.get("data");
                          iv.setImageBitmap(bmp);
  
  
                  }
  
          }
  
  }
  </code></pre>
  
  <p>logcat</p>
  
  <pre><code>W/dalvikvm(919): threadid=1: thread exiting with uncaught exception (group=0x41d7d930) 
  03-07 00:00:24.704: E/AndroidRuntime(919): FATAL EXCEPTION: main 
  03-07 00:00:24.704: E/AndroidRuntime(919): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.hyperlocal.tradeit/com.hyperlocal.tradeit.Activity_Camera}: java.lang.NullPointerException 
  03-07 00:00:24.704: E/AndroidRuntime(919): at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
  </code></pre>