Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin.Forms.Labs MediaPicker causing exception on Android

$
0
0

I am using Xamarin.Forms.Labs.Services.Media.IMediaPicker.TakePhotoAsync() to capture a photo on Android. The actual capture works fine, but at some point after the fact the following exception occurs. It seems to be occurring on the Final() of some object relating to the ImageRenderer.

09-29 14:54:58.793 E/mono    ( 4210): Unhandled Exception:
09-29 14:54:58.793 E/mono    ( 4210): System.ArgumentException: 'jobject' must not be IntPtr.Zero.
09-29 14:54:58.793 E/mono    ( 4210): Parameter name: jobject
09-29 14:54:58.793 E/mono    ( 4210):   at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod) [0x00000] in <filename unknown>:0 
09-29 14:54:58.793 E/mono    ( 4210):   at Android.Widget.ImageView.get_Drawable () [0x00000] in <filename unknown>:0 
09-29 14:54:58.793 E/mono    ( 4210):   at Xamarin.Forms.Platform.Android.ImageRenderer.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
09-29 14:54:58.793 E/mono    ( 4210):   at Java.Lang.Object.Finalize () [0x00000] in <filename unknown>:0 
09-29 14:54:58.823 D/AbsListView( 4210): unregisterIRListener() is called 
In mgmain JNI_OnLoad
The program 'Mono' has exited with code 0 (0x0).

The exception occurs about half the time on the first capture. If the exception does not occur on the first capture, it always occurs on the second.

Here is an abbreviated example of how I call it.

IMediaPicker mediaPicker = AcquireMediaPicker();
byte[] imageData;
using (MediaFile mediaFile = await mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions()))
{
        int length = (int)mediaFile.Source.Length ;
        imageData = new byte[length];
        mediaFile.Source.Read(imageData, 0, length);
}
// use data here

SelectPhotoAsync() behaves the same way.

I have reworked the code a half dozen different ways, and nothing changes. Does anyone have any insights?

Thanks,
Jon


Viewing all articles
Browse latest Browse all 58056

Trending Articles