当我调用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>有什么想法吗?
发布于 2013-05-10 22:51:00
我发现了一个奇怪的变通方法。我注意到,如果应用程序在尝试显示DatePickerDialog之前的任何时候打开一个AlertDialog,它都可以工作。所以这样做:
var helperDialog = new AlertDialog.Builder(this).SetTitle("").Show();
helperDialog.Hide();在返回OnCreateDialog中的DatePickerDialog之前,似乎可以解决这个问题。这是一个非常丑陋的变通方法,但它似乎对最终用户没有任何副作用。
不知道这是Android bug还是Monodroid bug。
https://stackoverflow.com/questions/16467859
复制相似问题