出现此错误 - CS0649字段' MainActivity.button1'永远不会分配给,并且将始终将其默认值设置为null

时间:2017-12-08 06:42:14

标签: c#

这是我的代码,我对C#来说是全新的,但是我遇到了一个改变TextView的按钮,以便在点击时说再见。

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;
using System;
using Java.Interop;
using Xamarin.Android.Net;

namespace FHoek
{
    [Activity(Label = "FHoek", MainLauncher = true)]
    public class MainActivity : Activity
    {
        private Button button1 ;
        private TextView textView1;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
        }
        public void ButtonPushed() {
            button1.Click += Button1_Click;
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            textView1.Text = ("Goodbye");
        }
    }


}

和xml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <TextView
        android:text="hello"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1" />
    <Button
        android:text="End"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button1"
        android:clickable="true"
        android:onClick="ButtonPushed"
        android:visibility="visible" />
</LinearLayout>

我不确定这里的问题是什么。我收到了button1和textView1的错误。

0 个答案:

没有答案