找不到构造函数... (System.IntPtr, Android.Runtime.JniHandleOwnership) [英] No constructor found for ... (System.IntPtr, Android.Runtime.JniHandleOwnership)

查看:24
本文介绍了找不到构造函数... (System.IntPtr, Android.Runtime.JniHandleOwnership)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里,我开始收到上述错误.
不是在这里和那里,而是无处不在.在某些地方我什至不能把这个奇怪的构造函数放进去,就像下面的调用堆栈.

In the last few days I started getting the error above.
Not here and there, but everywhere. and in places I can't even put this weird constructor in, like the call-stack below.

我在 https://stackoverflow.com/a/10603714/106248 中看到了答案,但我相信这是不是我的情况.它只是开始在任何地方发生.特别是当我放置断点时.

I saw the answer in https://stackoverflow.com/a/10603714/106248 but I believe this is not my case. It simply started happening everwhere. especially when I put a breakpoint.

这是一个例子:

10-26 15:34:58.895 E/mono-rt (13841): [ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Unable to activate instance of type Android.Views.View+IOnClickListenerImplementor from native handle 7960001d ---> System.MissingMethodException: No constructor found for Android.Views.View+IOnClickListenerImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
10-26 15:34:58.895 E/mono-rt (13841): Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
10-26 15:34:58.895 E/mono-rt (13841): 
10-26 15:34:58.895 E/mono-rt (13841):   --- End of managed exception stack trace ---
10-26 15:34:58.895 E/mono-rt (13841): java.lang.Error: Java callstack:
10-26 15:34:58.895 E/mono-rt (13841):   at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
10-26 15:34:58.895 E/mono-rt (13841):   at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
10-26 15:34:58.895 E/mono-rt (13841):   at android.view.View.performClick(View.java:4475)
10-26 15:34:58.895 E/mono-rt (13841):   at android.view.View$PerformClick.run(View.java:18786)
10-26 15:34:58.895 E/mono-rt (13841):   at android.os.Handler.handleCallback(Handler.java:730)
10-26 15:34:58.895 E/mono-rt (13841):   at android.os.Handler.dispatchMessage(Handler.java:92)
10-26 15:34:58.895 E/mono-rt (13841):   at android.os.Looper.loop

推荐答案

根据我的经验,当您的应用程序运行时从内存中释放对象时会发生这种情况.然后,例如,如果您返回到该页面并且需要由 Mono 重新创建该对象,则您需要指定该构造函数.

From what I experienced, this can happens when an object is released from memory while your application is running. Then, for instance, if you go back to that page and the object needs to be recreated by Mono, you need to specify that constructor.

John Pryor 您所指的答案 应该是您问题的答案.重要的部分如下:

The John Pryor answer you are referring to should be the answer to your problem. The important part is the following :

所以 Mono for Android 创建了一个适当类型的实例...via(IntPtr, JniHandleOwnership) 构造函数,并产生错误如果找不到此构造函数.

So Mono for Android creates an instance of the appropriate type...via the (IntPtr, JniHandleOwnership) constructor, and generates an error if this constructor cannot be found.

一旦(在本例中)TextView 构造函数完成执行,LogTextBox 的 ACW 构造函数将执行,此时 Mono forAndroid 会啊哈!我们已经为此创建了一个 C# 实例Java 实例",然后将调用适当的构造函数已经创建的实例.这意味着对于单个实例,两个将执行构造函数: (IntPtr, JniHandleOwnership)构造函数,以及(稍后)(Context、IAttributeSet、int)构造函数.

Once the (in this case) TextView constructor finishes executing, the LogTextBox's ACW constructor will execute, at which point Mono for Android will go "aha! we've already created a C# instance for this Java instance", and will then invoke the appropriate constructor on the already created instance. Meaning that for a single instance, two constructors will be executed: the (IntPtr, JniHandleOwnership) constructor, and (later) the (Context, IAttributeSet, int) constructor.

我想成为一个更好的帮助,但没有任何代码片段很难说.尝试查看实现 IOnClickListenerImplementor 的对象,看看是否可以在侦听器的实现中添加构造函数......祝你好运

I'd like to be a better help, but without any code snippet it's hard to tell. Try looking in object which implements the IOnClickListenerImplementorsee if you can add the constructor in the implementation of the listener.... Good luck

这篇关于找不到构造函数... (System.IntPtr, Android.Runtime.JniHandleOwnership)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆