1
votes

My Xamarin forms projects Crashes randomly in Android Device with runtime Exception "System.ObjectDisposedException: Cannot access a disposed object". Full Exception details of Exception is provided below.

Xamarin caused by: android.runtime.JavaProxyThrowable:
    System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'Android.Graphics.Bitmap'.
    Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable
    self)<324eef0d9faf40c68e8ccba861935530>:0
    Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeAbstractVoidMethod(string
    encodedMember, IJavaPeerable self, JniArgumentValue*
    parameters)<324eef0d9faf40c68e8ccba861935530>:0
    Android.Graphics.Bitmap.Recycle()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.ButtonDrawable.Reset()<7999cc4bd5664eca8a72469344172ca3>:0
    Xamarin.Forms.Platform.Android.ButtonDrawable.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Java.Lang.Object.Dispose()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.ButtonBackgroundTracker.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Xamarin.Forms.Platform.Android.ButtonBackgroundTracker.Dispose()<7999cc4bd5664eca8a72469344172ca3>:0
    Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Java.Lang.Object.Dispose()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.VisualElementRenderer<TElement>.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Java.Lang.Object.Dispose()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.ListViewAdapter.DisposeOfConditionalFocusLayout(ConditionalFocusLayout
    layout)<7999cc4bd5664eca8a72469344172ca3>:0
    Xamarin.Forms.Platform.Android.ListViewAdapter.DisposeCells()<7999cc4bd5664eca8a72469344172ca3>:0
    Xamarin.Forms.Platform.Android.ListViewAdapter.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Java.Lang.Object.Dispose()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.ListViewRenderer.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Java.Lang.Object.Dispose()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.VisualElementRenderer<TElement>.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Xamarin.Forms.Platform.Android.PageRenderer.Dispose(bool
    disposing)<7999cc4bd5664eca8a72469344172ca3>:0
    Java.Lang.Object.Dispose()<73ab2c5689214855b48bbe2f2fb4fb55>:0
    Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnDestroyView()<7999cc4bd5664eca8a72469344172ca3>:0
    Android.Support.V4.App.Fragment.n_OnDestroyView(IntPtr jnienv,
    IntPtr native__this)<1e89c43d3c7d48b5ba69bfc0b1bdf114>:0 at (wrapper
    dynamic-method)
    System.Object.f520c17a-44d9-4d27-b6fa-0401b7b5794a(intptr,intptr)
    md5270abb39e60627f0f200893b490a1ade.FragmentContainer.n_onDestroyView(Native
    Method)
    md5270abb39e60627f0f200893b490a1ade.FragmentContainer.onDestroyView()FragmentContainer.java:41
    android.support.v4.app.Fragment.performDestroyView()Fragment.java:2480
    android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1422
    android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState()FragmentManager.java:1569
    android.support.v4.app.BackStackRecord.executeOps()BackStackRecord.java:753
    android.support.v4.app.FragmentManagerImpl.executeOps()FragmentManager.java:2415
    android.support.v4.app.FragmentManagerImpl.executeOpsTogether()FragmentManager.java:2201
    android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps()FragmentManager.java:2155
    android.support.v4.app.FragmentManagerImpl.execPendingActions()FragmentManager.java:2064
    android.support.v4.app.FragmentManagerImpl$1.run()FragmentManager.java:718
    android.os.Handler.handleCallback()Handler.java:754
    android.os.Handler.dispatchMessage()Handler.java:95
    android.os.Looper.loop()Looper.java:163
    android.app.ActivityThread.main()ActivityThread.java:6221
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:904
    com.android.internal.os.ZygoteInit.main()ZygoteInit.java:794

We cannot find the disposed object . If any one has any solution for it please help us.

2

2 Answers

0
votes

I had this issue, in a Page where it had a Listview. The problem was related to the views, while scrolling, and disposing. After I switched the CachingStrategy to RecycleElement, the problem was fixed. Since you haven't posted any code/any way to reproduce, check if this is the case.

0
votes

I noticed the ButtonBackgroundTracker and ButtonDrawable on the top of your stacktrace.

I had a simular issue with crashes at startup of a Xamarin Forms project. Causer of the crash was an incompatible style causing a crash in android. My advice is to comment out the android styles and narrow down which style (probably button) is causing the crash.

There are a number of results on stackoverflow about incompatible styles causing this type of exception, for example InflateException with FloatingActionButton from Official Design Library