title: Xamarin - Null pointer exception when trying to start Activity outside the Main Activity?
body: <p>I have an app and here is the first code block </p>
  
  <pre><code>public class MainActivity : Activity
  {
  
      protected override void OnCreate(Bundle oBundle)
      {
          base.OnCreate(oBundle);
  
          SetContentView(Resource.Layout.Layout_Main);
  
          FragmentTransaction oFragmentTransaction = FragmentManager.BeginTransaction();
          SlidingTabsFragment oSlidingTabsFragment = new SlidingTabsFragment();
  
          oFragmentTransaction.Replace(Resource.Id.SampleContentFragment, oSlidingTabsFragment);
  
          oFragmentTransaction.Commit();
      }
  </code></pre>
  
  <p>This app has a Swiping Tab Layout and I create a custom Sliding Tab Fragment. Here  is the SlidingTabsFragment Class Code </p>
  
  <pre><code>public class SlidingTabsFragment : Fragment
  {
      public override View OnCreateView(LayoutInflater oLayoutInflater, ViewGroup oViewGroup, Bundle savedInstanceState)
      {
          return oLayoutInflater.Inflate(Resource.Layout.Layout_SlidingLayoutBase, oViewGroup, false);
      }
  
      public override void OnViewCreated(View oView, Bundle savedInstanceState)
      {
          SlidingTabScrollView oSlidingTabScrollView = oView.FindViewById&lt;SlidingTabScrollView&gt;(Resource.Id.SlidingLayout_SlidingTabScrollView);
  
          ViewPager oViewPager = oView.FindViewById&lt;ViewPager&gt;(Resource.Id.SlidingLayout_ViewPager);
  
          oViewPager.Adapter = new TabPageAdapter();
  
          oSlidingTabScrollView.ViewPager = oViewPager;
      }
  }
  </code></pre>
  
  <p>So on SlidingTabFragment inherits from Fragment - on create view it inflates the layout and onViewCreated it Sets Up SlidingTabScrollView, ViewPager and TabPageAdapter. Tab page adapter has a bit of code that takes care of TabItem Contents. </p>
  
  <p>So here is my problem: </p>
  
  <p>On of the TabItems has a listview - and I am listening for an OnClick Event. The Goal Is To Start a New Activity When I catch this event. </p>
  
  <p>I get a Java.Lang.NullPointerException and here it is. I have tried adding Activity name in the Manifest File but it did not make a difference. I went through at least 10 posts about it and could not get an idea of why is not it starting it. If I catch a ButtonBackPRess and insert my snippet there it works just fine.</p>
  
  <pre><code>Intent oIntent = new Intent(this, typeof(SignInActivity));
          StartActivity(oIntent);
  </code></pre>
  
  <p>It is this TabLayout and different classes that does not let me see a clear picture of what is going on. Why can not I start the activity fellows?</p>
  
  <pre><code>  Java.Lang.NullPointerException: 
  at at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () &lt;IL 0x00011, 0x00068&gt;
    at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
    at Android.Content.ContextWrapper.StartActivity (Android.Content.Intent) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Content.ContextWrapper.cs:2895
    at MyAppName.TabLayouts..ctor (Android.Views.ViewGroup) [0x0003d] in c:\Xamarin\MyAppName\MyAppName\TabLayouts.cs:41
    at MyAppName.TabPageAdapter.InstantiateItem (Android.Views.ViewGroup,int) [0x00001] in c:\Xamarin\MyAppName\MyAppName\TabPageAdapter.cs:44
    at at Android.Support.V4.View.PagerAdapter.n_InstantiateItem_Landroid_view_ViewGroup_I (intptr,intptr,intptr,int) &lt;IL 0x00014, 0x000ff&gt;
    at at (wrapper dynamic-method) object.19196691-50f4-44b8-a7cd-7a7ffc0f8179 (intptr,intptr,intptr,int) &lt;IL 0x0001d, 0x0004f&gt;
    at --- End of managed exception stack trace ---
    at java.lang.NullPointerException
    at at android.app.Activity.startActivityForResult(Activity.java:3511)
    at at android.app.Activity.startActivityForResult(Activity.java:3472)
    at at android.app.Activity.startActivity(Activity.java:3714)
    at at android.app.Activity.startActivity(Activity.java:3682)
    at at MyAppName.TabPageAdapter.n_instantiateItem(Native Method)
    at at MyAppName.TabPageAdapter.instantiateItem(TabPageAdapter.java:47)
    at at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:837)
    at at android.support.v4.view.ViewPager.populate(ViewPager.java:987)
    at at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
    at at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
    at at android.view.View.measure(View.java:17387)
    at at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
    at at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at at android.view.View.measure(View.java:17387)
    at at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at at android.view.View.measure(View.java:17387)
    at at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
    at at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at at android.view.View.measure(View.java:17387)
    at at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at at android.view.View.measure(View.java:17387)
    at at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
    at at android.view.View.measure(View.java:17387)
    at at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
    at at android.view.View.measure(View.java:17387)
    at at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2211)
    at at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1350)
    at at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1547)
    at at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1234)
    at at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6465)
    at at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
    at at android.view.Choreographer.doCallbacks(Choreographer.java:603)
    at at android.view.Choreographer.doFrame(Choreographer.java:573)
    at at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
    at at android.os.Handler.handleCallback(Handler.java:733)
    at at android.os.Handler.dispatchMessage(Handler.java:95)
    at at android.os.Looper.loop(Looper.java:157)
    at at android.app.ActivityThread.main(ActivityThread.java:5356)
    at at java.lang.reflect.Method.invokeNative(Native Method)
    at at java.lang.reflect.Method.invoke(Method.java:515)
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Manifest File</p>
  
  <pre><code> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="MyAppName.MyAppName" android:versionCode="1" android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="15" /&gt;
      &lt;application android:label="MyAppName" android:icon="@drawable/Icon" android:theme="@style/CustomActionBarTheme"&gt;&lt;/application&gt;
      &lt;activity android:name=".TestActivity"/&gt;
      &lt;activity android:name=".MainActivity"/&gt;
      &lt;activity android:name=".SignInActivity"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;/manifest&gt;
  </code></pre>