title: Kivy on Android, JVM exception occurred: Attempt to invoke virtual method ... on a null object reference
body: <p>We're trying to access the Android camera in the Kivy app we're building. We first opted to use <code>plyer</code> but we were getting a <code>ClipData.Item.getUri()</code> error. We ended up trying to follow the details described here: <a href="https://github.com/kivy/plyer/issues/500#issuecomment-565532048" rel="nofollow noreferrer">https://github.com/kivy/plyer/issues/500#issuecomment-565532048</a></p>
  
  <p>Now there seems to be a problem in getting the URI for a file.</p>
  
  <p>We have added this in <code>AndroidManifest.tmpl.xml</code>:</p>
  
  <pre><code>&lt;manifest&gt;
      &lt;application&gt;
      ...
  
      &lt;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="org.our.appnamehere"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/file_paths"/&gt;
      &lt;/provider&gt;
  
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>and this in the <code>file_paths.xml</code> as well:</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="external_files"  path="Android/data/org.our.appnamehere/files/Pictures"  /&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>We've tried changing the <code>android:authorities</code> line into <code>org.our.appnamehere.provider</code> and <code>org.our.appnamehere.fileprovider</code>as well as changing the corresponding <code>getUriForFile</code> in the given file from the link above</p>
  
  <pre><code>...
  
  photo_file = self._create_image_file()
  
  if photo_file is not None:
      photo_uri = FileProvider.getUriForFile(
                      self.currentActivity.getApplicationContext(),
                      self.currentActivity.getApplicationContext().getPackageName(),
                      photo_file
                  )
  
  ...
  </code></pre>
  
  <p>into either <code>self.currentActivity.getApplicationContext().getPackageName() + '.provider'</code> or <code>self.currentActivity.getApplicationContext().getPackageName() + '.fileprovider'</code>. </p>
  
  <p>The app seems to be successful in creating the file that <code>photo_file</code> links to, as we can access them under <code>Android/data/org.our.appnamehere/files/Pictures</code>. We always get the following error, presumably from the <code>photo_uri</code> line:</p>
  
  <pre><code>JavaException("JVM Exception occurred: 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")
  </code></pre>
  
  <p>The smartphone on which we are running the compiled app is on Android Pie, Version 9.</p>
  
  <p>Nearly all solutions to this error just looks like the ones we have added into the manifest and the file_paths.xml. In addition to the several variations of <code>android:authorities</code>, we also tried the following lines from this link: <a href="https://github.com/jkwiecien/EasyImage/issues/103#issuecomment-304304045" rel="nofollow noreferrer">https://github.com/jkwiecien/EasyImage/issues/103#issuecomment-304304045</a></p>
  
  <pre><code>        &lt;provider
              ...
              tools:replace="android:authorities"&gt;
              &lt;meta-data
                  ...
                  tools:replace="android:resource"/&gt;
          &lt;/provider&gt;
  </code></pre>
  
  <p>They do not really work and we still can't access the camera. We might just be missing something obvious...</p>
  
  <p>Any help would be greatly appreciated. Thank you very much.</p>