title: Xamarin Forms MainActivity OnCreate LoadApplication System.NullReferenceException: Object reference not set to an instance of an object
body: <p>I am using VS2015 with Xamarin to create a multi-platform project that can show a splashscreen and then load a webpage in a webview. Here is my project structure. I am using a PCL project type as below:</p>
  
  <p><a href="https://i.stack.imgur.com/op1Zw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/op1Zw.png" alt="enter image description here"></a></p>
  
  <p><em>TheApp (Portable)</em></p>
  
  <pre><code>-WebPageHoster.Xaml     //Contains a WebView control
     -WebPageHoster.Xaml.cs  //sets the WebView controls source property to load a webpage
     -App.Xaml
     -App.Xaml.cs
  </code></pre>
  
  <p><em>TheApp.Droid</em></p>
  
     <pre class="lang-xml prettyprint-override"><code>/Resources/drawable/splashlogo.png
  /Resources/drawable/icon3.png
  /Resources/values/Styles.xml
  -MainActivity.cs
  -SplashActivity.cs     
  </code></pre>
  
  <p><em>TheApp.iOS</em></p>
  
  <p><em>TheApp.WindowsPhone(Windows Phone 8.1)</em></p>
  
  <p>This is the code in the <code>Styles.xml</code></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; 
  &lt;resources&gt;
      &lt;style name="Theme.Splash" parent="android:Theme"&gt;
          &lt;item name="android:windowBackground"&gt;@drawable/splashlogo&lt;/item&gt;
          &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt;
      &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><em>SplashActivity.cs</em></p>
  
  <pre class="lang-cs prettyprint-override"><code>[Activity(MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash", Icon = "@drawable/icon3")]
  public class SplashActivity : AppCompatActivity
  {
      protected override void OnCreate(Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);
          var intent = new Intent(this, typeof(MainActivity));
          StartActivity(intent);
          Finish();
      }
  }
  </code></pre>
  
  <p><em>MainActivity.cs</em></p>
  
  <pre class="lang-cs prettyprint-override"><code>[Activity(Label = "Splash App",  ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
  public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
  {
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
          global::Xamarin.Forms.Forms.Init(this, bundle);
          LoadApplication(new App());  // &lt;&lt; Problem here
      }
  </code></pre>
  
  <p>The <code>LoadApplication</code> method call in the <code>OnCreate</code> method above loads the app constructor of the App.Xaml.cs class which runs the following code</p>
  
  <p>public App()
      {
          InitializeComponent();
          MainPage = new NavigationPage(new WebPageHoster() { Title = "Load Web-Page" });
      }</p>
  
  <p>This shows the splash screen and after setting the WebView's url reaches back to the OnCreate method and gives this error</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object
  </code></pre>
  
  <p>I am unable to find what is causing this error. Here is the Android Manifest file.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="TheApp.TheApp" android:installLocation="auto" android:versionCode="1"&gt;
      &lt;uses-sdk android:minSdkVersion="15" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt;
      &lt;application android:icon="@drawable/icon3" android:theme="@style/Theme.AppCompat" android:label="Splash Web Host"&gt;&lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>