在Android 2上调用ShowDialog时出现NullReferenceException

在Android 2上调用ShowDialog时出现NullReferenceException,android,xamarin.android,Android,Xamarin.android,当调用Acitiviy.ShowDialog(int)响应用户点击按钮时,我得到一个NullReferenceException。该异常出现在Android 2.1中,但不在Android 4.2中。以下是Stacktrace: UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at (wrapper delegate-invoke) &

当调用Acitiviy.ShowDialog(int)响应用户点击按钮时,我得到一个NullReferenceException。该异常出现在Android 2.1中,但不在Android 4.2中。以下是Stacktrace:

UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at (wrapper delegate-invoke) <Module>.invoke_void__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x000b3>
at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00053>
at Android.App.Activity.ShowDialog (int) <0x0011f>
at MyApp.AndroidApp.InvoiceActivity.ShowScheduleDateDialog (object,System.EventArgs) <0x0003b>
at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) <0x00057>
at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) <0x00063>
at (wrapper dynamic-method) object.be0dcca3-9ca4-47b4-a6a4-f691d34675f1 (intptr,intptr,intptr) <0x00043>
未处理的异常:System.NullReferenceException:对象引用未设置为对象的实例
at(包装委托调用)。调用\u void\u this\u intptr\u intptr\u intptr\u JValue[](intptr、intptr、intptr、Android.Runtime.JValue[])
在Android.Runtime.JNIEnv.CallVoidMethod(intptr、intptr、Android.Runtime.JValue[])中
在Android.App.Activity.ShowDialog(int)上
在MyApp.AndroidApp.InvoiceActivity.ShowScheduleDateDialog(对象,System.EventArgs)
在Android.Views.View/IOnClickListenerImplementor.OnClick(Android.Views.View)
在Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_View_View_(intptr、intptr、intptr)
at(包装器动态方法)object.be0dcca3-9ca4-47b4-a6a4-f691d34675f1(intptr、intptr、intptr)

有什么想法吗?

我找到了一个奇怪的解决办法。我注意到,如果该应用程序在试图显示DatePickerDialog之前的任何时候打开AlertDialog,它都可以工作。这样做:

var helperDialog = new AlertDialog.Builder(this).SetTitle("").Show();
helperDialog.Hide();
在OnCreateDialog中返回DatePickerDialog之前,似乎解决了这个问题。这是一个非常难看的解决方法,但它似乎对最终用户没有任何副作用


不知道这是Android bug还是Monodroid bug。

您应该发布代码本身,我们将无法帮助您。