title: FileProvider.getUriForFile returns NullPointerException
body: <p>I'm trying to write my first android app, which will involve taking a picture and doing stuff with it. </p>
  
  <p>I've put together some code after looking at several tutorials online but am getting the following NullPointerException whenever the button is clicked:</p>
  
  <pre><code>10-03 14:48:00.284 26310-26310/org.broadinstitute.jsnap E/MainActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
  10-03 14:48:00.293 26310-26310/org.broadinstitute.jsnap E/MYAPP: exception
                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
                                                                       at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:583)
                                                                       at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:557)
                                                                       at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:399)
                                                                       at org.broadinstitute.jsnap.MainActivity.takePhoto(MainActivity.java:54)
                                                                       at org.broadinstitute.jsnap.MainActivity.access$000(MainActivity.java:24)
                                                                       at org.broadinstitute.jsnap.MainActivity$1.onClick(MainActivity.java:43)
                                                                       at android.view.View.performClick(View.java:6205)
                                                                       at android.widget.TextView.performClick(TextView.java:11103)
                                                                       at android.view.View$PerformClick.run(View.java:23653)
                                                                       at android.os.Handler.handleCallback(Handler.java:751)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6682)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
  </code></pre>
  
  <p>I'm not quite sure how to resolve. Here's my relevant code:</p>
  
  <p>manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.broadinstitute.jsnap"&gt;
  
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-feature android:name="android.hardware.camera" android:required="true"/&gt;
      &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
      &lt;uses-feature android:name="android.hardware.camera.flash" android:required="false"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          &gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;provider
              android:name="android.support.v4.content.FileProvider"
              android:authorities="${applicationId}.fileprovider"
              android:exported="false"
              android:grantUriPermissions="true"&gt;
              &lt;meta-data
                  android:name="android.support.FILE_PROVIDER_PATHS"
                  android:resource="@xml/file_paths"&gt;&lt;/meta-data&gt;
          &lt;/provider&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>file_paths.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;paths xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;external-path name="jsnap_images" path="Android/data/org.broadinstitute.jsnap/files/Pictures" /&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>And MainActivity:</p>
  
  <pre><code>package org.broadinstitute.jsnap;
  
  import android.app.Activity;
  import android.content.ContentResolver;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.net.Uri;
  import android.os.Build;
  import android.os.Environment;
  import android.provider.MediaStore;
  import android.support.v4.content.FileProvider;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.Toast;
  import java.io.File;
  import java.io.IOException;
  import java.util.jar.Manifest;
  
  
  public class MainActivity extends Activity {
      private static String logtag = "MainActivity";
      private static int TAKE_PICTURE = 1;
      private static final String AUTHORITY = "org.broadinstitute.jsnap.provider";
      private static final String PHOTOS="photos";
      private static final String FILENAME="jsnap_test.jpeg";
      Uri imageURI;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Button cameraButton = (Button)(findViewById(R.id.cam_button));
          cameraButton.setOnClickListener(cameraListener);
  
      }
      private View.OnClickListener cameraListener = new View.OnClickListener() {
          public void onClick(View v) {
              try {
                  takePhoto(v);
              } catch (Exception e) {
                  Log.e(logtag, e.toString());
              }
          }
      };
      private void takePhoto(View v){
          Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
          File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), FILENAME);
          imageURI=FileProvider.getUriForFile(this, AUTHORITY, photo);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, imageURI);
          // TAKE_PICTURE is a request code saying we want to use the rear-facing camera.
          startActivityForResult(intent, TAKE_PICTURE);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
          super.onActivityResult(requestCode, resultCode, intent);
  
          if(resultCode == Activity.RESULT_OK) {
              Uri selectedImage = imageURI;
              getContentResolver().notifyChange(selectedImage, null);
  
              ImageView imageView = (ImageView)findViewById(R.id.image_camera);
              ContentResolver cr = getContentResolver();
              Bitmap bitmap;
  
              try {
                  bitmap = MediaStore.Images.Media.getBitmap(cr, selectedImage);
                  imageView.setImageBitmap(bitmap);
                  Toast.makeText(MainActivity.this, selectedImage.toString(), Toast.LENGTH_SHORT).show();
              } catch(Exception e) {
                  Log.e(logtag, e.toString());
              }
          }
      }
  }
  </code></pre>
  
  <p>Any help is greatly appreciated. </p>