2
votes

Get exception when take photo from my android app. I used Media Plugin https://github.com/jamesmontemagno/MediaPlugin

   var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                        {
                            PhotoSize = PhotoSize.Medium,
                            Directory = "Sample",
                            Name = "test.jpg"
                        }); 

{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 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in :0 at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in :0 at Android.Support.V4.Content.FileProvider.GetUriForFile (Android.Content.Context context, System.String authority, Java.IO.File file) [0x00078] in <3e239b9681084d42bb949c1e01ef500e>:0
at Plugin.Media.MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0023f] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:162

--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 at Plugin.Media.MediaImplementation+d__16.MoveNext () [0x000c7] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaImplementation.cs:119

--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 at Propznet.Mobile.Features.Inventory.Helpers.UnitCreateUpdateViewModelBase+<b__32_0>d.MoveNext () [0x00091] in E:\Propznet Mobile\Source\Propznet.Mobile\Propznet.Mobile.Features.Inventory\Helpers\UnitCreateUpdateViewModelBase.cs:322 --- End of managed Java.Lang.NullPointerException stack trace --- 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:583) at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:557) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:399) at md5f1b52d9f1d5d1981437e7e130649468a.MediaPickerActivity.n_onCreate(Native Method) at md5f1b52d9f1d5d1981437e7e130649468a.MediaPickerActivity.onCreate(MediaPickerActivity.java:42) at android.app.Activity.performCreate(Activity.java:6259) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5459) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) }

3
What is your app's target version? Did you add meta-data in your android project's manifest and create a new xml called "file_path.xml"?Grace Feng
Android 7.0 .file_path?Jinesh
Check the read me part of the lib you used, in the ANDROID N part.Grace Feng
Did these comments solved your problem?Grace Feng
Yes, its workingJinesh

3 Answers

2
votes

As james montemagno mentioned

You MUST set your Target version to API 23+ and Compile against API 23+:

enter image description here

0
votes

Check the read me of the library you used, in the ANDROID N part (as stated by Grace Feng in the comments above).

0
votes

I had the same error, when I run the app in release mode, in debug it was ok. So I switched in properties of Android project on Android options page Liking from SDK Assemblies only to None. It solved my problem.