title: Run time error in Android TabLayout using ViewPager and Fragments
body: <p>I am create a TabLayout application in android using ViewPager and Fragments.And i am successfully build the application.But after installing apk to device,my app is unfortunately stopped.Please help me to fix the problem.</p>
  
  <p><strong>MainActiviti.java</strong></p>
  
  <pre><code>  package com.asoft.admin.anto_tab;  
  import android.support.design.widget.TabLayout;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.os.Bundle;
  
  public class MainActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener {
  
  //This is our tablayout
  private TabLayout tabLayout;
  
  //This is our viewPager
  private ViewPager viewPager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      //Adding toolbar to the activity
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      //Initializing the tablayout
      tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  
      //Adding the tabs using addTab() method
      tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
      tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
      tabLayout.addTab(tabLayout.newTab().setText("Tab3"));
      tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
  
      //Initializing viewPager
      viewPager = (ViewPager) findViewById(R.id.pager);
  
      //Creating our pager adapter
      Pager adapter = new Pager(getSupportFragmentManager(), tabLayout.getTabCount());
  
      //Adding adapter to pager
      viewPager.setAdapter(adapter);
  
      //Adding onTabSelectedListener to swipe views
      tabLayout.setOnTabSelectedListener(this);
  
  
  }
  
  @Override
  public void onTabSelected(TabLayout.Tab tab) {
  
  }
  
  @Override
  public void onTabUnselected(TabLayout.Tab tab) {
  
  }
  
  @Override
  public void onTabReselected(TabLayout.Tab tab) {
  
  }
  }
  </code></pre>
  
  <p><strong>Pager.java</strong></p>
  
  <pre><code>package com.asoft.admin.anto_tab;
  /**
   * Created by Admin on 27-07-2016.
   */
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * Created by Belal on 2/3/2016.
  */
  
  //Our class extending fragment
  public class Tab1 extends Fragment {
  
  //Overriden method onCreateView
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      //Returning the layout file after inflating
      //Change R.layout.tab1 in you classes
      return inflater.inflate(R.layout.tab1, container, false);
  }
  }
  </code></pre>
  
  <p><strong>Tab1.java</strong></p>
  
  <pre><code>package com.asoft.admin.anto_tab;
  /**
   * Created by Admin on 27-07-2016.
   */
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * Created by Belal on 2/3/2016.
  */
  
  //Our class extending fragment
  public class Tab1 extends Fragment {
  
  //Overriden method onCreateView
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      //Returning the layout file after inflating
      //Change R.layout.tab1 in you classes
      return inflater.inflate(R.layout.tab1, container, false);
  }
  }
  </code></pre>
  
  <p><strong>Tab2.java</strong></p>
  
  <pre><code> package com.asoft.admin.anto_tab;
  
  /**
   * Created by Admin on 27-07-2016.
   */
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * Created by Belal on 2/3/2016.
   */
  
  //Our class extending fragment
  public class Tab2 extends Fragment {
  
  //Overriden method onCreateView
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      //Returning the layout file after inflating
      //Change R.layout.tab1 in you classes
      return inflater.inflate(R.layout.tab1, container, false);
  }
  }
  </code></pre>
  
  <p><strong>Tab3.java</strong></p>
  
  <pre><code> package com.asoft.admin.anto_tab;
  
  /**
   * Created by Admin on 27-07-2016.
  */
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * Created by Belal on 2/3/2016.
   */
  
  //Our class extending fragment
  public class Tab3 extends Fragment {
  
  //Overriden method onCreateView
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      //Returning the layout file after inflating
      //Change R.layout.tab1 in you classes
      return inflater.inflate(R.layout.tab1, container, false);
  }
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  tools:context=".MainActivity"&gt;
  
  
  &lt;!-- our toolbar --&gt;
  &lt;android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?attr/colorPrimary"
      android:minHeight="?attr/actionBarSize"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/&gt;
  
  &lt;!-- our tablayout to display tabs  --&gt;
  &lt;android.support.design.widget.TabLayout
      android:id="@+id/tabLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?attr/colorPrimary"
      android:minHeight="?attr/actionBarSize"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/&gt;
  
  &lt;!-- View pager to swipe views --&gt;
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"/&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Logcat</strong></p>
  
  <pre><code>07-27 12:21:46.909 2529-2529/com.asoft.admin.anto_tab I/art: Not late- enabling -Xcheck:jni (already on)
  07-27 12:21:47.080 2529-2529/com.asoft.admin.anto_tab W/System: ClassLoader  referenced unknown path: /data/app/com.asoft.admin.anto_tab-1/lib/x86
  07-27 12:22:01.740 2529-2529/com.asoft.admin.anto_tab W/System: ClassLoader referenced unknown path: /data/app/com.asoft.admin.anto_tab-1/lib/x86
  07-27 12:22:01.988 2529-2529/com.asoft.admin.anto_tab W/art: Before Android  4.1, method android.graphics.PorterDuffColorFilter   android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.     graphics.PorterDuffColorFilter, android.content.res.ColorStateList,  android.graphics.PorterDuff$Mode) would have incorrectly overridden the package- private method in android.graphics.drawable.Drawable
  07-27 12:22:02.124 2529-2529/com.asoft.admin.anto_tab D/AndroidRuntime:  Shutting down VM
  
  
                                                                      --------- beginning of crash
  07-27 12:22:02.124 2529-2529/com.asoft.admin.anto_tab E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process:  com.asoft.admin.anto_tab, PID: 2529
                                                                       java.lang.RuntimeException: Unable to start activity  ComponentInfo{com.asoft.admin.anto_tab/com.asoft.admin.anto_tab.MainActivity}:  java.lang.IllegalStateException: This Activity already has an action bar  supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR  and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                          at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                          at  android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                          at  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                          at  android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at  android.os.Looper.loop(Looper.java:148)
                                                                          at  android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                          at  java.lang.reflect.Method.invoke(Native Method)
                                                                          at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                          at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                       Caused  by: java.lang.IllegalStateException: This Activity already has an action bar  supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR  and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                          at  android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDele gateImplV7.java:198)
                                                                          at  android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:130)
                                                                          at com.asoft.admin.anto_tab.MainActivity.onCreate(MainActivity.java:25)
                                                                          at android.app.Activity.performCreate(Activity.java:6237)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                          at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at   android.os.Looper.loop(Looper.java:148) 
                                                                          at  android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                          at  java.lang.reflect.Method.invoke(Native Method) 
                                                                          at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  07-27 12:22:07.113 2529-2535/com.asoft.admin.anto_tab W/art: Suspending all  threads took: 5.201ms
  07-27 12:22:22.184 2529-2535/com.asoft.admin.anto_tab W/art: Suspending all threads took: 19.789ms
  07-27 12:22:22.350 2529-2529/com.asoft.admin.anto_tab I/Process: Sending  signal.    PID: 2529 SIG: 9
  </code></pre>
  
  <p><strong>styles.xml</strong></p>
  
  <pre><code>&lt;resources&gt;
  
  &lt;!-- Base application theme. --&gt;
  &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
      &lt;!-- Customize your theme here. --&gt;
      &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
      &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
      &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p></p>