I was just trying to make a simple app with Xamarin.android from the tutorial shown https://learn.microsoft.com/en-us/learn/modules/create-a-mobile-app-with-xamarin-forms/5-exercise-create-phone-number-translator-app 
But when I build it, application crashes. I tried debugging and got an error in OnTranslate method as System.NullReferenceException: Object reference not set to an instance of an object. 
I tried setting values of declared variables as null. Tried using null operator.
This is my code
    {
        Entry phoneNumberText = null;
        Button translateButton = null;
        Button callButton = null;
        string translatedNumber;
        public MainPage()
        {
           /*
               Some design code
           */
            translateButton.Clicked += OnTranslate;
            this.Content = panel;
        }
         void OnTranslate(object sender, EventArgs e)
        {
            string enterednum = phoneNumberText.Text;
            translatedNumber = Core.PhonewordTranslator.ToNumber(enterednum);
            if (!string.IsNullOrEmpty(translatedNumber))
            {
                callButton.IsEnabled = true;
                callButton.Text = "Call" + translatedNumber;
            }
            else
            {
                callButton.IsEnabled = false;
                callButton.Text = "Call";
            }
        }
I have set the values for entry and those two buttons in my design code. And this is the method to translate string to number
        {
            if (string.IsNullOrWhiteSpace(raw))
                return null;
            raw = raw?.ToUpperInvariant();
            var newNumber = new StringBuilder();
            foreach (var c in raw)
            {
                if (" -0123456789".Contains(c))
                    newNumber?.Append(c);
                else
                {
                    var result = TranslateToNumber(c);
                    if (result != null)
                        newNumber.Append(result);
                    //bad string?
                    else return null;
                }
            }
            return newNumber?.ToString();
        }
        static bool Contains(this string keystring, char c){
            return keystring?.IndexOf(c) >= 0;
            }
        static readonly string[] digits =
        {
            "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"
        };
        static int? TranslateToNumber(char c)
        {
            for(int i = 0; i<digits.Length; i++)
            {
                if (digits[i].Contains(c))
                    return 2 + i;
            }
            return null;
        }
    }
 
    