title: When i run the android tab swipe getting error
body: <pre><code>package actions.com.mytabswipe;
  
  import android.app.ActionBar;
  import android.app.FragmentTransaction;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.view.ViewPager;
  
  
  public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
  
      ViewPager viewPager;
      TabAdapter tabAdapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          tabAdapter = new TabAdapter(getSupportFragmentManager());
          final ActionBar actionBar = getActionBar();
          actionBar.setHomeButtonEnabled(false);
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
          viewPager = (ViewPager) findViewById(R.id.viewPAger);
          viewPager.setAdapter(tabAdapter);
          viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
              @Override
              public void onPageSelected(int position) {
                  actionBar.setSelectedNavigationItem(position);
              }
          });
          for (int i = 0; i &lt; tabAdapter.getCount(); i++) {
              actionBar.addTab(actionBar.newTab().setText("Tab " + i).setTabListener(this));
          }
      }
      @Override
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
          viewPager.setCurrentItem(tab.getPosition());
      }
      @Override
      public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
      }
      @Override
      public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
      }
  }
  </code></pre>
  
  <blockquote>
    <p>when i run this am getting error 02-03 04:40:10.277:
    E/AndroidRuntime(2378): FATAL EXCEPTION: main 02-03 04:40:10.277:
    E/AndroidRuntime(2378): Process: actions.com.mytabswipe, PID: 2378
    02-03 04:40:10.277: E/AndroidRuntime(2378):
    java.lang.RuntimeException: Unable to start activity
    ComponentInfo{actions.com.mytabswipe/actions.com.mytabswipe.MainActivity}:
    java.lang.NullPointerException 02-03 04:40:10.277:
    E/AndroidRuntime(2378):   at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    android.app.ActivityThread.access$800(ActivityThread.java:135) 02-03
    04:40:10.277: E/AndroidRuntime(2378):     at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    android.os.Handler.dispatchMessage(Handler.java:102) 02-03
    04:40:10.277: E/AndroidRuntime(2378):     at
    android.os.Looper.loop(Looper.java:136) 02-03 04:40:10.277:
    E/AndroidRuntime(2378):   at
    android.app.ActivityThread.main(ActivityThread.java:5017) 02-03
    04:40:10.277: E/AndroidRuntime(2378):     at
    java.lang.reflect.Method.invokeNative(Native Method) 02-03
    04:40:10.277: E/AndroidRuntime(2378):     at
    java.lang.reflect.Method.invoke(Method.java:515) 02-03 04:40:10.277:
    E/AndroidRuntime(2378):   at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 02-03
    04:40:10.277: E/AndroidRuntime(2378):     at
    dalvik.system.NativeStart.main(Native Method) 02-03 04:40:10.277:
    E/AndroidRuntime(2378): Caused by: java.lang.NullPointerException
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    actions.com.mytabswipe.MainActivity.onCreate(MainActivity.java:23)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    android.app.Activity.performCreate(Activity.java:5231) 02-03
    04:40:10.277: E/AndroidRuntime(2378):     at
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
    02-03 04:40:10.277: E/AndroidRuntime(2378):   ... 11 more</p>
    
    <p>My Custom Adapter package actions.com.mytabswipe;</p>
    
    <p>import android.support.v4.app.Fragment; import
    android.support.v4.app.FragmentManager; import
    android.support.v4.app.FragmentPagerAdapter; import
    android.support.v4.app.FragmentStatePagerAdapter;</p>
    
    <p>/**  * Created by Murali on 03-Feb-15.  */ public class TabAdapter
    extends FragmentPagerAdapter {</p>
  
  <pre><code>public TabAdapter(FragmentManager manager) {
      super(manager);
  
  }
  
  @Override
  public Fragment getItem(int position) {
  
  
      switch (position) {
          case 0:
              new Fragment1();
          case 1:
            new Fragment2();
      }
      return new Fragment1();
  }
  
  @Override
  public int getCount() {
      return 2;
  } } My fragment, package actions.com.mytabswipe;
  </code></pre>
    
    <p>import android.os.Bundle; import android.support.annotation.Nullable;
    import android.support.v4.app.Fragment; import
    android.view.LayoutInflater; import android.view.View; import
    android.view.ViewGroup;</p>
    
    <p>/**  * Created by Murali on 03-Feb-15.  */ public class Fragment2
    extends Fragment {</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater,  ViewGroup container, Bundle savedInstanceState) {
      return inflater.inflate(R.layout.fragment2,container,false);
  } }
  </code></pre>
  </blockquote>