title: Xamarin Android passing MainActivity to AlertDialog
body: <p>I am trying to implement the AlertDialog by separating its code in another class and calling that class as required in the code.</p>
  
  <p>Here is how i have my AlertDialog</p>
  
  <pre><code> using Android.App;
   using Android.Content;
   using Android.OS;
   using Android.Runtime;
   using Android.Views;
   using Android.Widget;
  
  
  namespace NAndroid
  {
     public class AlertViewController: Activity
     {
         public AlertViewController ()
         {
         }
  
          public void ShowAlertBox (string titleTxt, string messageTxt)
          {
  
             AlertDialog.Builder builder = new AlertDialog.Builder(this);
             builder.SetTitle(titleTxt);
             builder.SetMessage(messageTxt);
             builder.SetCancelable(false);
             builder.SetPositiveButton("OK", delegate { Finish(); });
             RunOnUiThread (() =&gt; {
              builder.Show();
             } );
         }
       }
    }
  </code></pre>
  
  <p>To call it from other class</p>
  
  <pre><code>AlertViewController alertView = new AlertViewController ();
  alertView.ShowAlertBox ("Test", "Test");
  </code></pre>
  
  <p>It is crashing at the line. It throws Null Pointer Exception</p>
  
  <pre><code> AlertDialog.Builder builder = new AlertDialog.Builder(this);
  </code></pre>