title: Android Save Image to New Folder
body: <p>I'm trying to save pictures that I took awhile ago into a different folder (the folder already exists).  My manifest is up to date on permissions that I need, and I know I need to use something along the lines of: </p>
  
  <pre><code>MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);  
  </code></pre>
  
  <p>The following is my code.  What am I doing wrong that it won't save?   Thank you!</p>
  
  <p>save.setOnClickListener(new View.OnClickListener() {</p>
  
  <pre><code>@Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  
  int id = viewIt.getId();
  
  String root = Environment.getExternalStorageDirectory().toString();
  String myDir = new String(root + "/New Directory/Folder 1/"); 
  String description = "";
  String filestring = arrPath[id];        
  try {
      MediaStore.Images.Media.insertImage(getContentResolver(), myDir, filestring, description);
      } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } 
      sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
      Uri.parse("file://" +  Environment.getExternalStorageDirectory())));
  
      Toast.makeText(getApplicationContext(), "Save Successful", Toast.LENGTH_SHORT).show();          
  
  
      }
  });
  </code></pre>
  
  <p>Here are the errors from my logcat:</p>
  
  <pre><code>04-20 17:38:03.763: E/AndroidRuntime(1003): FATAL EXCEPTION: main
  04-20 17:38:03.763: E/AndroidRuntime(1003): java.lang.NullPointerException
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:551)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at com.test.Import$ImageAdapter$2$4$1.onClick(Import.java:339)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.view.View.performClick(View.java:2485)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.view.View$PerformClick.run(View.java:9080)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.os.Handler.handleCallback(Handler.java:587)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.os.Handler.dispatchMessage(Handler.java:92)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.os.Looper.loop(Looper.java:123)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at java.lang.reflect.Method.invokeNative(Native Method)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at java.lang.reflect.Method.invoke(Method.java:507)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  04-20 17:38:03.763: E/AndroidRuntime(1003):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>