title: "Object reference not set to an instance of an object" in Xamarin.android c#
body: <p>I was just trying to make a simple app with Xamarin.android from the tutorial shown <a href="https://docs.microsoft.com/en-us/learn/modules/create-a-mobile-app-with-xamarin-forms/5-exercise-create-phone-number-translator-app" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/learn/modules/create-a-mobile-app-with-xamarin-forms/5-exercise-create-phone-number-translator-app</a> 
  But when I build it, application crashes. I tried debugging and got an error in OnTranslate method as <code>System.NullReferenceException: Object reference not set to an instance of an object.</code>  </p>
  
  <p>I tried setting values of declared variables as null. Tried using null operator.</p>
  
  <p>This is my code </p>
  
  <pre><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";
              }
          }
  </code></pre>
  
  <p>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</p>
  
  <pre><code>        {
              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) &gt;= 0;
              }
  
          static readonly string[] digits =
          {
              "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"
          };
          static int? TranslateToNumber(char c)
          {
              for(int i = 0; i&lt;digits.Length; i++)
              {
                  if (digits[i].Contains(c))
                      return 2 + i;
              }
              return null;
          }
      }
  </code></pre>