Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No constructor found for ... (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.

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.

Here is an example:

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
like image 777
Hagai L Avatar asked Oct 26 '14 13:10

Hagai L


1 Answers

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.

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

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.

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.

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

like image 91
ForceMagic Avatar answered Oct 15 '22 12:10

ForceMagic