Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Xamarin Android。按钮单击需要的事件帮助_C#_Xamarin_Xamarin.android - Fatal编程技术网

C#Xamarin Android。按钮单击需要的事件帮助

C#Xamarin Android。按钮单击需要的事件帮助,c#,xamarin,xamarin.android,C#,Xamarin,Xamarin.android,我厌倦了用xamarin做一个简单的a+B加法程序,但每次点击按钮都会出现system.NullReferenceException错误 Button button = FindViewById<Button>(Resource.Id.button1); button.Click += delegate { EditText number1 = FindViewById<EditText>(Resource.Id.editText1

我厌倦了用xamarin做一个简单的a+B加法程序,但每次点击按钮都会出现system.NullReferenceException错误

Button button = FindViewById<Button>(Resource.Id.button1);
        button.Click += delegate {
            EditText number1 = FindViewById<EditText>(Resource.Id.editText1);
            EditText number2 = FindViewById<EditText>(Resource.Id.editText2);
            TextView res = FindViewById<TextView>(Resource.Id.textView1);
            int result = Convert.ToInt32(number1.Text) + Convert.ToInt32(number2.Text);
            res.Text = result.ToString();
        };
Button-Button=findviewbyd(Resource.Id.button1);
按钮。单击+=委派{
EditText number1=FindViewById(Resource.Id.editText1);
EditText number2=FindViewById(Resource.Id.editText2);
TextView res=findviewbyd(Resource.Id.textView1);
int result=Convert.ToInt32(number1.Text)+Convert.ToInt32(number2.Text);
res.Text=result.ToString();
};

您注释掉了该行:

SetContentView(Resource.Layout.Main);
此操作将当前活动“绑定”到内容视图。 如果你不绑定,你的程序就找不到像按钮这样的元素。因此,它会给您一个对象引用错误


因此,删除SetContentView前面的//,它应该可以工作。

您注释掉了这行:

SetContentView(Resource.Layout.Main);
此操作将当前活动“绑定”到内容视图。 如果你不绑定,你的程序就找不到像按钮这样的元素。因此,它会给您一个对象引用错误


因此,删除SetContentView前面的//,它应该可以工作。

您没有设置活动内容
SetContentView(Resource.Layout.Main)
您没有设置活动内容
SetContentView(Resource.Layout.Main)
您好,很抱歉,您的解决方案工作了,重新启动成功了:)非常感谢。您好,很抱歉,您的解决方案工作了,重新启动成功了:)非常感谢