【问题标题】:DefaultRenderer error in xamarin.forms (Android)xamarin.forms (Android) 中的 DefaultRenderer 错误
【发布时间】:2018-09-12 03:08:15
【问题描述】:

我正在使用 xamarin 表单...有时当我尝试返回上一页时,我会看到这个(Android 设备):

System.NotSupportedException:无法从本机句柄 0xbeb4a30c 激活 Xamarin.Forms.Platform.Android.Platform+DefaultRenderer 类型的实例

我在标签渲染器和框渲染器中看到了同样的问题,但我通过在自定义渲染器中创建构造函数解决了这个问题,如下面的链接所示:

MonoDroid: Error when calling constructor of custom view - TwoDScrollView

但是在过去 30 天里我搜索的所有地方都没有关于 DefaultRenderer 错误的任何信息……我快疯了……

完全例外:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbecdf3ac (key_handle 0x24da7695).

04-04 11:51:53.914 D/Mono    (30832): DllImport attempting to load: '/system/lib/liblog.so'. 04-04 11:51:53.914 D/Mono    (30832): DllImport loaded library '/system/lib/liblog.so'. 04-04 11:51:53.914 D/Mono    (30832): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so'). 04-04 11:51:53.914 D/Mono    (30832): Searching for '__android_log_print'. 04-04 11:51:53.914 D/Mono    (30832): Probing '__android_log_print'. 04-04 11:51:53.914 D/Mono    (30832): Found as '__android_log_print'. 04-04 11:51:53.924 I/MonoDroid(30832): UNHANDLED EXCEPTION: 04-04 11:51:53.944 I/MonoDroid(30832): System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbecdf3ac (key_handle 0x24da7695). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.Platform+DefaultRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. 04-04 11:51:53.944 I/MonoDroid(30832):    --- End of inner exception stack trace --- 04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):    --- End of inner exception stack trace --- 04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00000] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:51:53.944 I/MonoDroid(30832):   at (wrapper dynamic-method) System.Object:cce836e4-e6e4-4d51-a0da-36412953d80b (intptr,intptr,intptr) 04-04 11:51:53.964 W/art     (30832): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable 04-04 11:51:53.964 D/Mono    (30832): DllImport searching in: '__Internal' ('(null)'). 04-04 11:51:53.964 D/Mono    (30832): Searching for 'java_interop_jnienv_throw'. 04-04 11:51:53.964 D/Mono    (30832): Probing 'java_interop_jnienv_throw'. 04-04 11:51:53.964 D/Mono    (30832): Found as 'java_interop_jnienv_throw'. Unhandled Exception:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbecdf3ac (key_handle 0x24da7695).

04-04 11:51:57.014 I/art     (30832): Thread[2,tid=30839,WaitingInMainSignalCatcherLoop,Thread*=0xaf90e400,peer=0x12c4d080,"Signal Catcher"]: reacting to signal 3 04-04 11:51:57.584 I/art     (30832): Wrote stack traces to '/data/anr/traces.txt' 04-04 11:52:07.844 I/MonoDroid(30832): UNHANDLED EXCEPTION: 04-04 11:52:07.894 I/MonoDroid(30832): System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbecdf3ac (key_handle 0x24da7695). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.Platform+DefaultRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. 04-04 11:52:07.894 I/MonoDroid(30832):    --- End of inner exception stack trace --- 04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):    --- End of inner exception stack trace --- 04-04 11:52:07.894 I/MonoDroid(30832):   at (wrapper dynamic-method) System.Object:cce836e4-e6e4-4d51-a0da-36412953d80b (intptr,intptr,intptr) 04-04 11:52:07.894 I/MonoDroid(30832):   at (wrapper managed-to-native) Java.Interop.NativeMethods:java_interop_jnienv_call_nonvirtual_void_method_a (intptr,intptr&,intptr,intptr,intptr,Java.Interop.JniArgumentValue*) 04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00073] in <e8c0e16a54534fa885244f0ad837c79e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e8c0e16a54534fa885244f0ad837c79e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Android.Views.ViewGroup.RemoveAllViews () [0x0000a] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing) [0x00088] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:238 04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Lang.Object.Dispose () [0x00000] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.ListViewRenderer.ClearRenderer (Android.Views.View renderedView) [0x00032] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\Renderers\ListViewRenderer.cs:295 04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.ListViewRenderer.Dispose (System.Boolean disposing) [0x0001e] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\Renderers\ListViewRenderer.cs:59 04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Lang.Object.Dispose () [0x00000] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing) [0x0007b] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:234 04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Lang.Object.Dispose () [0x00000] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing) [0x0007b] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:234 04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.PageRenderer.Dispose (System.Boolean disposing) [0x00011] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\Renderers\PageRenderer.cs:33 04-04 11:52:07.894 I/MonoDroid(30832):   at Java.Lang.Object.Dispose () [0x00000] in <e79c73bcbbb547688bef6c7e9665c95e>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnDestroyView () [0x0003c] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:91 04-04 11:52:07.894 I/MonoDroid(30832):   at Android.Support.V4.App.Fragment.n_OnDestroyView (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <1e89c43d3c7d48b5ba69bfc0b1bdf114>:0  04-04 11:52:07.894 I/MonoDroid(30832):   at (wrapper dynamic-method) System.Object:1df32498-cacf-4686-8c6a-cd4a5d878faf (intptr,intptr) 04-04 11:52:07.914 E/mono-rt (30832): Stacktrace: 04-04 11:52:07.914 E/mono-rt (30832):  04-04 11:52:07.914 E/mono-rt (30832):   at <unknown> <0xffffffff> 04-04 11:52:07.914 E/mono-rt (30832):   at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jnienv_new_string (intptr,intptr&,char*,int) <0x00043> 04-04 11:52:07.914 E/mono-rt (30832):   at Java.Interop.JniEnvironment/Strings.NewString (char*,int) [0x00009] in <e8c0e16a54534fa885244f0ad837c79e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at Java.Interop.JniEnvironment/Strings.NewString (string) [0x00024] in <e8c0e16a54534fa885244f0ad837c79e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at Android.Runtime.JNIEnv.NewString (string) [0x0000a] in <e79c73bcbbb547688bef6c7e9665c95e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at Java.Lang.Error..ctor (string) [0x00020] in <e79c73bcbbb547688bef6c7e9665c95e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at Android.Runtime.JavaProxyThrowable..ctor (System.Exception) [0x00007] in <e79c73bcbbb547688bef6c7e9665c95e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at Java.Lang.Throwable.FromException (System.Exception) [0x0001e] in <e79c73bcbbb547688bef6c7e9665c95e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at Android.Runtime.AndroidEnvironment.UnhandledException (System.Exception) [0x00068] in <e79c73bcbbb547688bef6c7e9665c95e>:0 04-04 11:52:07.924 E/mono-rt (30832):   at (wrapper dynamic-method) object.1df32498-cacf-4686-8c6a-cd4a5d878faf (intptr,intptr) [0x00029] in <657aa8fea4454dc898a9e5f379c58734>:0 04-04 11:52:07.924 E/mono-rt (30832):   at (wrapper native-to-managed) object.1df32498-cacf-4686-8c6a-cd4a5d878faf (intptr,intptr) [0x00021] in <657aa8fea4454dc898a9e5f379c58734>:0 04-04 11:52:07.924 E/mono-rt (30832): /proc/self/maps:

【问题讨论】:

  • 您在导航返回时是否使用某种动画进行视图或页面转换?扔得太快时,我遇到了视图动画的一些问题。我在执行动画之前调用Task.Yield() 解决了它。
  • 我使用的是xamarin的默认导航...
  • 我也间歇性地遇到同样的问题。我很惊讶没有人在任何地方回答这个问题。
  • 请分享mvce

标签: android mobile xamarin.forms renderer


【解决方案1】:

这应该通过使用旧的 JNI 构造函数和旧的渲染器来解决

public MyLabelRenderer(IntPtr handle, JniHandleOwnership transfer)
{
}

并通过在 MainActivity 中设置 UseLegacyRenderers 标志

Forms.SetFlags("UseLegacyRenderers");

【讨论】:

    猜你喜欢
    • 2020-07-11
    • 2021-05-24
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 2016-08-26
    • 1970-01-01
    相关资源
    最近更新 更多