[SOLVED]Error at Taking picture with intents(Need Serious Help)

Code:
mPhotoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Uri uri = FileProvider.getUriForFile(getActivity(), "com.lite_industries.samm.criminalintent.fileprovider", mPhotoFile); captureImage.putExtra(MediaStore.EXTRA_OUTPUT, uri); List<ResolveInfo> cameraActivities = getActivity() .getPackageManager().queryIntentActivities(captureImage, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo activity : cameraActivities) { getActivity().grantUriPermission(activity.activityInfo.packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } startActivityForResult(captureImage, REQUEST_PHOTO); } });
Android Manifest:
<provider android:authorities="com.lite_industries.sam.criminalintent.CrimeFragment.FileProvider" android:name="android.support.v4.content.FileProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/files"/> </provider>
XML:(files.xml)
<?xml version="1.0" encoding="utf-8"?> <paths> <files-path name="crime_photos" path="."/> </paths>
This is the error I get after I did everything(help needed)
StackTrace:

01-21 13:52:30.758 17431-17431/com.lite_industries.sam.criminalintent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lite_industries.sam.criminalintent, PID: 17431
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:591)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:565)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:403)
at com.lite_industries.sam.criminalintent.CrimeFragment$6.onClick(CrimeFragment.java:144)
at android.view.View.performClick(View.java:5657)
at android.view.View$PerformClick.run(View.java:22453)
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:6236)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

Please check the authority value in the following two parts.
They are different in your code.


Uri uri = FileProvider.getUriForFile(getActivity(), 
"com.lite_industries.samm.criminalintent.fileprovider", mPhotoFile); 

<provider 
    android:authorities="com.lite_industries.sam.criminalintent.CrimeFragment.FileProvider" 
    android:name="android.support.v4.content.FileProvider" 
    android:exported="false" 
    android:grantUriPermissions="true">
    <meta-data 
        android:name="android.support.FILE_PROVIDER_PATHS" 
        android:resource="@xml/files"/> 
</provider>

Okay the “sam” alone should be changed or the whole authority value should be same???

According to the reference, they should be exactly same.
Please check the “Generating the Content URI for a File” part.

https://developer.android.com/reference/android/support/v4/content/FileProvider.html#GetUri

1 Like

Thanks for the reply. That saved.