2

Hi I'm currently experiencing error on starting an intent due to FileProvider causing NPE. I followed the steps provided here but I still got the error:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

I am not sure as well if the provider_paths.xml is being used here. Here's my code so far:

Manifest:

<application>... <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider></application>

res/xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

code:

Uri uri=FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID+".provider", file);

the itself seems to be the cause of error here.

KaHeL
  • 4,301
  • 16
  • 54
  • 78
  • 1
    I'm not sure why I get a down vote on this question. I know some will say this is a duplicate but I already checked on every solution I can find here and it all says the same. For now I opt to just use: StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); sad thing SO community. :( – KaHeL Jun 29 '17 at 07:35

3 Answers3

0

BuildConfig.APPLICATION_ID should return your packagename, however, in my case it returned "android.support.v4". I consider using getPackagename() and it will work just fine!

So just change

FileProvider.getUriForFile(this,
                            BuildConfig.APPLICATION_ID + ".provider", file);

to:

FileProvider.getUriForFile(this,
                            getPackagename() + ".provider", file);
Timo Schuck
  • 314
  • 3
  • 11
0

Refer to this link for your answer. enter link description here

First, this:

android:authorities="${applicationId}.fileprovider"

you are using this:

FileProvider.getUriForFile(this,
                            BuildConfig.APPLICATION_ID + ".provider", file);

chabge this :

FileProvider.getUriForFile(this,
                            BuildConfig.APPLICATION_ID + ".fileprovider", file);

Since I don't know which of those is what you really want, I cannot suggest a fix.

-1

I am using this :

Manifest :

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

XML file :

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="media_folder" path="." />
</paths>

In Java :

FileProvider.getUriForFile(this,
                                BuildConfig.APPLICATION_ID + ".provider", file);
SANAT
  • 8,489
  • 55
  • 66