title: Using ActionBar Inside Fragment class in android
body: <p>I am trying to create Sliding tabs inside fragment . By referring tutorial from <a href="https://www.youtube.com/watch?v=heR4zhj_wV0" rel="nofollow">this</a> link. I am using <code>ViewPager</code> it. 
      Below is the my code :-</p>
  
  <pre><code>   public class A extends Fragment {
  
  
      private ViewPager pager;
      private TabsAdapter mTabsAdapter;
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState)
      {
          super.onActivityCreated(savedInstanceState);
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
      }
  
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState)
      {
  
          // TODO Auto-generated method stub
          View v = LayoutInflater.from(getActivity()).inflate(R.layout.one_fragment,
                  null);
  
          pager = new ViewPager(getActivity());
          pager.setId(R.id.pager);
          getActivity().setContentView(pager);
  
          final ActionBar bar = getActivity().getActionBar();
          bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          mTabsAdapter = new TabsAdapter(getActivity(), pager);
          mTabsAdapter.addTab(bar.newTab().setText("Mixed"), MixedFragment.class, null);
          mTabsAdapter.addTab(bar.newTab().setText("Income"), MixedFragment.class, null);
          mTabsAdapter.addTab(bar.newTab().setText("Expense"), MixedFragment.class, null);
  
  
          return v;
      }
  
  
  }
  </code></pre>
  
  <p>When I run the application it gives null pointer exception at </p>
  
  <pre><code> final ActionBar bar = getActivity().getActionBar();
              bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  </code></pre>
  
  <p>Please anyone tell me how to solve this problem.
  Or give me some sample code to create sliding tabs inside <code>Fragment</code>(Not <code>FragmentActivity</code>).
  Thanks in advance.</p>
  
  <p>Below is my manifest file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.hm.example"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="11"
          android:targetSdkVersion="19" /&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.CAMERA" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Holo.Light"&gt;
          &lt;activity
              android:name="com.hm.example.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Below is what my logcat is showing : </p>
  
  <pre><code>   FATAL EXCEPTION: main
  java.lang.NullPointerException
  at com.hm.A.onCreateView(A.java:49)
  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
  at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
  at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
  at android.os.Handler.handleCallback(Handler.java:605)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:4424)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>