Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser #103

Closed
amigax opened this issue Feb 1, 2017 · 12 comments

Comments

@amigax
Copy link

amigax commented Feb 1, 2017

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
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:560)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at pl.aprilapps.easyphotopicker.EasyImageFiles.getUriToFile(EasyImageFiles.java:142)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at pl.aprilapps.easyphotopicker.EasyImage.createCameraPictureFile(EasyImage.java:56)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at pl.aprilapps.easyphotopicker.EasyImage.createCameraIntent(EasyImage.java:86)

@iagomontenegrob
Copy link

+1

@RuslanTroshkov
Copy link

Add this code to your manifest file :

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

@pedrofsn
Copy link

pedrofsn commented Oct 2, 2017

It's solved! Thanks @RuslanTroshkov!

@filipef101
Copy link

@malavancs check issue #200

@dibyanshupatnaik
Copy link

dibyanshupatnaik commented Mar 2, 2018

Hi. I'm new to android programming and am stuck up in a similar way.

As suggested:
android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.easyphotopicker.fileprovider"

I have changed those lines in my manifest to:
android:name="android.support.v4.content.FileProvider" android:authorities="${com.example.android.trialcamera}.trialcamera.fileprovider"
with my applicationId being com.example.android.trialcamera.

But it seems like I'm making some mistake as I'm getting the same error as above:
Process: com.example.android.trialcamera, PID: 7389
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:584)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:558)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at com.example.android.trialcamera.MainActivity.takePicture(MainActivity.java:92)
at com.example.android.trialcamera.MainActivity$1.onClick(MainActivity.java:84)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

And this is the snippet of the code which appears to be a problem:
`public void takePicture(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = Uri.fromFile(getOutputMediaFile());
file = FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName()+ "com.example.android.trialcamera", getOutputMediaFile() );
intent.putExtra(MediaStore.EXTRA_OUTPUT, file);

        startActivityForResult(intent, 100);
    }`

@vijayanandkh
Copy link

I think the file path provider path mentioned in manifest and one being used in start activity have different package path. I mean you missed the subpackage "trialcamera" missing.

As i see in Manifest you mentioned:
${com.example.android.trialcamera}.trialcamera.fileprovider"

While in source code accessing the fileprovider using
getApplicationContext().getPackageName()+ "com.example.android.trialcamera"

You can add in source as this way:

FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName()+ ".trialcamera.fileprovider", getOutputMediaFile() );

or, hard code the package path as

ileProvider.getUriForFile(MainActivity.this, "com.example.android.trialcamera.fileprovider", getOutputMediaFile() );

One thing to look is the authority mentioned in manifest should be same as that being used in source file to get file URI.

@arupnayak
Copy link

Use the fully qualified name of the cordova plugin in the provider tag in android manifest file.
Eg: android:name="io.github.pwlin.cordova.plugins.fileopener2.FileProvider"

Similar issue i was facing in fileopener plugin. See the resolution below
pwlin/cordova-plugin-file-opener2#215 (comment)

@sharibtanweer
Copy link

Non Of This Which GitHub Or Anywhere It Provider Pattern Working In Android 8.

@iamadityaaz
Copy link

And in paths.xml i put <paths> <root-path name="root" path="." /> </paths>

@johnshardman
Copy link

Add this code to your manifest file :

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

How is tools defined?

@callmeblue
Copy link

Add this code to your manifest file :

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

How is tools defined?

xmlns:tools="http://schemas.android.com/tools"

@johnshardman
Copy link

Thank you @callmeblue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests