在异常中找不到构造函数,但类具有确切的构造函数

时间:2018-05-22 12:19:01

标签: xamarin xamarin.android

我有时会遇到以下异常:

Unhandled Exception: Android.Runtime.JavaProxyThrowable: Exception of type 'Android.Runtime.JavaProxyThrowable' was thrown.
  --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type TaxiTabletUniversal.Droid.Views.SoftMeterView from native handle 0xbe8cfb2c (key_handle 0x369e8281). ---> System.MissingMethodException: No constructor found for TaxiTabletUniversal.Droid.Views.SoftMeterView::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at Android.Views.ViewTreeObserver+IOnGlobalLayoutListenerInvoker.n_OnGlobalLayout (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <5ade030ddd6b4e4c9dda56516f1de4fe>:0 
  at (wrapper dynamic-method) System.Object.90422e09-526e-4347-b02e-8c2980bde53e(intptr,intptr)
    at mvvmcross.droid.views.MvxActivity.n_onGlobalLayout(Native Method)
    at mvvmcross.droid.views.MvxActivity.onGlobalLayout(MvxActivity.java:84)
    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:986)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2221)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1306)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7031)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:821)
    at android.view.Choreographer.doCallbacks(Choreographer.java:606)
    at android.view.Choreographer.doFrame(Choreographer.java:576)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:807)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6914)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

从那个例外中突出的一点说:

找不到TaxiTabletUniversal.Droid.Views.SoftMeterView ::。ctor(System.IntPtr,Android.Runtime.JniHandleOwnership)的构造函数

但是SoftmeterView类(派生自MvxActivity)确实有2个构造函数:

public SoftMeterView() : base()
{
    MoveTaskToBack(true);
    IsCreated = true;
}

第二个匹配精确签名,异常抱怨:

public SoftMeterView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
    MoveTaskToBack(true);
    IsCreated = true;
}

有什么想法吗?

0 个答案:

没有答案