LavanKumar
LavanKumar

Reputation: 21

java.lang.NullPointerException:

Follwing is the code piece which works in my sample project.but it is not working in my actual project.

 await CrossMedia.Current.Initialize();
 if (!CrossMedia.Current.IsCameraAvailable||!CrossMedia.Current.IsTakePhotoSupported)
 {
   await DisplayAlert("No Camera", ":( No camera available.", "OK");
   return;
  }
 var filePath = await CrossMedia.Current.TakePhotoAsync(newPlugin.Media.Abstractions.StoreCameraMediaOptions
  {
     SaveToAlbum = true
  });

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:560)
    at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
    at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)
    at md5a3e164e78ade0c22cefea770ddd0bc49.MediaPickerActivity.n_onCreate(NativeMethod)     at md5a3e164e78ade0c22cefea770ddd0bc49.MediaPickerActivity.onCreate(MediaPickerActvity.java:42)
    at android.app.Activity.performCreate(Activity.java:6092)

Upvotes: 0

Views: 941

Answers (2)

Uddhao Pachrne
Uddhao Pachrne

Reputation: 551

I got above problem even I already did all above things. I got fixed this issue in my case for android to set "Use Latest Platform(Android7.1)" for "Compile Using android version: (Target Framework)" in "Application" tab of android project properties.

Upvotes: 0

Gerald Versluis
Gerald Versluis

Reputation: 33993

Besides adding the right permissions, please make sure you have added the additional file_paths.xml file under a folder called xml in the Resources folder in your Android project if you are targetting Android N (API level 24+).

It should look like this:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="my_images" path="Android/data/YOUR_APP_PACKAGE_NAME/files/Pictures" />
    <external-path name="my_movies" path="Android/data/YOUR_APP_PACKAGE_NAME/files/Movies" />
</paths>

Where YOUR_APP_PACKAGE_NAME must be set to your app package name!

Then add this in your `application` tag in the `androidmanifest.xml` file:

<provider android:name="android.support.v4.content.FileProvider" 
                android:authorities="YOUR_APP_PACKAGE_NAME.fileprovider" 
                android:exported="false" 
                android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" 
                android:resource="@xml/file_paths"></meta-data>
</provider>

Again, make sure your YOUR_APP_PACKAGE_NAME is set to your app package name.

For more on what you need to configure when using this plugin, please make sure you read the documentation on the Github page

Upvotes: 5

Related Questions