dimonovdd / Xamarin.MediaGallery

This plugin is designed to picking and save images and video files from native gallery of Android and iOS devices and capture photos
MIT License
154 stars 19 forks source link

Java.Lang.NullPointerException: uri #136

Open Simoo23 opened 2 weeks ago

Simoo23 commented 2 weeks ago

Description

Hello, I saw sometimes in AppCenter these 2 errors:

Error 1: mono.java.lang.RunnableImplementor.run Java.Lang.NullPointerException: uri

Stacktrace:

Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualObjectMethod(JniObjectReference , JniObjectReference , JniMethodInfo , JniArgumentValue* )
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualObjectMethod(String , IJavaPeerable , JniArgumentValue* )
Android.Content.ContentResolver.OpenInputStream(Uri )
NativeMedia.MediaFile.PlatformOpenReadAsync()
NativeMedia.MediaFile.OpenReadAsync()
App.Services.PhotoService.MediaFileService.ReadPhotoAsync(IMediaFile photo)
java.lang.NullPointerException: uri
java.util.Objects.requireNonNull Objects.java:232
android.content.ContentResolver.openInputStream ContentResolver.java:1501
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run RunnableImplementor.java:31
android.os.Handler.handleCallback Handler.java:938
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loopOnce Looper.java:210
android.os.Looper.loop Looper.java:299
android.app.ActivityThread.main ActivityThread.java:8280
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:576
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1073

Error 2:

androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick Java.Lang.NullPointerException: uri

Stacktrace:

Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualObjectMethod(JniObjectReference , JniObjectReference , JniMethodInfo , JniArgumentValue* )
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualObjectMethod(String , IJavaPeerable , JniArgumentValue* )
Android.Content.ContentResolver.OpenInputStream(Uri )
NativeMedia.MediaFile.PlatformOpenReadAsync()
NativeMedia.MediaFile.OpenReadAsync()
App.Services.PhotoService.MediaFileService.ReadPhotoAsync(IMediaFile photo)
java.lang.NullPointerException: uri
java.util.Objects.requireNonNull Objects.java:245
android.content.ContentResolver.openInputStream ContentResolver.java:1508
androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.n_onClick(Native Method)
androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick AlertDialog_IDialogInterfaceOnClickListenerImplementor.java:31
androidx.appcompat.app.AlertController$ButtonHandler.handleMessage AlertController.java:167
android.os.Handler.dispatchMessage Handler.java:106
android.os.Looper.loopOnce Looper.java:226
android.os.Looper.loop Looper.java:313
android.app.ActivityThread.main ActivityThread.java:8663
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:571
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1135

Expected behavior

No errors

Steps to reproduce the behavior

I have not reproduced the problem on my devices

Configuration

Plugin Version: 2.2.1

I saw in devices with:

and other Xiaomi phones

dimonovdd commented 2 weeks ago

I have only 1 suggestion: Add logs before await MediaGallery.PickAsync(...) and before await mediaFile.PlatformOpenReadAsync().

You should check if the activity instances are different from Microsoft.Maui.ApplicationModel.Platform.CurrentActivity