我的Xamarin表单项目在Android设备中随机崩溃,并带有以下运行时异常

时间:2018-07-19 07:43:40

标签: forms xamarin objectdisposedexception

我的Xamarin表单项目在Android设备中随机崩溃,运行时异常为“ System.ObjectDisposedException:无法访问已处置的对象”。 下面提供了Exception的完整Exception详细信息。

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

我们找不到被处置的物体。如果有任何解决方案,请帮助我们。

2 个答案:

答案 0 :(得分:0)

我在一个具有Listview的Page中遇到了这个问题。问题与滚动和处置时的视图有关。将CachingStrategy切换为RecycleElement后,问题已解决。由于您尚未发布任何代码/任何方式进行复制,因此请检查这种情况。

答案 1 :(得分:0)

我注意到了堆栈跟踪顶部的ButtonBackgroundTracker和ButtonDrawable。

我在启动Xamarin Forms项目时遇到了类似的崩溃问题。 崩溃的原因是一种不兼容的样式,导致android崩溃。 我的建议是注释掉android样式,并缩小导致崩溃的样式(可能是按钮)。

关于导致这种类型的异常的不兼容样式的大量关于堆栈溢出的结果,例如 InflateException with FloatingActionButton from Official Design Library