title: TabLayout with ViewPager leading to app crash
body: <p>I want to make a GUI for android app where I have TabLayout for separate fragments. Uptil now my MainActivity.java and activity_main.xml look like this:</p>
  
  <p><strong>MainActivity.java:</strong></p>
  
  <pre><code>package com.example.cortana.testing.activity;
  
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.Toolbar;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import com.example.cortana.testing.R;
  
  
  import com.example.cortana.testing.fragments.Fragment_A;
  import com.example.cortana.testing.fragments.Fragment_B;
  
  
  
  
  public class MainActivity extends AppCompatActivity {
  
      private Toolbar toolbar;
      private TabLayout tabLayout;
      private ViewPager viewPager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          viewPager = (ViewPager) findViewById(R.id.viewpager);
          setupViewPager(viewPager);
  
          tabLayout = (TabLayout) findViewById(R.id.tabs);
          tabLayout.setupWithViewPager(viewPager);
      }
  
      private void setupViewPager(ViewPager viewPager) {
          ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
          adapter.addFragment(new Fragment_A(), "A");
          adapter.addFragment(new Fragment_B(), "B");
          viewPager.setAdapter(adapter);
      }
  
      class ViewPagerAdapter extends FragmentPagerAdapter {
          private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
          private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
          public ViewPagerAdapter(FragmentManager manager) {
              super(manager);
          }
  
          @Override
          public Fragment getItem(int position) {
              return mFragmentList.get(position);
          }
  
          @Override
          public int getCount() {
              return mFragmentList.size();
          }
  
          public void addFragment(Fragment fragment, String title) {
              mFragmentList.add(fragment);
              mFragmentTitleList.add(title);
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return mFragmentTitleList.get(position);
          }
      }
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:layout_scrollFlags="scroll|enterAlways"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light" &gt;
          &lt;/android.support.v7.widget.Toolbar&gt;
  
          &lt;android.support.design.widget.TabLayout
              android:id="@+id/tabs"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:tabMode="fixed"
              app:tabGravity="fill" &gt;
          &lt;/android.support.design.widget.TabLayout&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"  &gt;
      &lt;/android.support.v4.view.ViewPager&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>Other things (fragments and their layouts) have been properly setup. Now, the problem is that when I include the tablayout with viewPager using the funtion <code>tabLayout.setupWithViewPager(viewPager);</code> present on <code>line 44</code> of MainActivity.java, the app crashes. App doesn't crash and runs as expected (without tabs on the bar but fragments present). 
  The app crash report is here:</p>
  
  <pre><code>06-23 11:23:05.949 21271-21271/com.example.cortana.testing E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.cortana.testing, PID: 21271
  java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/internal/widget/TintManager;
  at android.support.design.widget.TabLayout$TabView.&lt;init&gt;(TabLayout.java:1145)
  at android.support.design.widget.TabLayout.createTabView(TabLayout.java:635)
  at android.support.design.widget.TabLayout.addTabView(TabLayout.java:669)
  at android.support.design.widget.TabLayout.addTab(TabLayout.java:365)
  at android.support.design.widget.TabLayout.addTab(TabLayout.java:340)
  at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:624)
  at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:595)
  at com.example.cortana.testing.activity.MainActivity$override.onCreate(MainActivity.java:44)
  at com.example.cortana.testing.activity.MainActivity$override.access$dispatch(MainActivity.java)
  at com.example.cortana.testing.activity.MainActivity.onCreate(MainActivity.java:0)
  at android.app.Activity.performCreate(Activity.java:6220)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2646)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4324)
  at android.app.ActivityThread.access$900(ActivityThread.java:182)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
  at android.os.Handler.dispatchMessage(Handler.java:111)
  at android.os.Looper.loop(Looper.java:194)
  at android.app.ActivityThread.main(ActivityThread.java:5763)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)                                                                               Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.widget.TintManager" on path: DexPathList[[dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-support-annotations-23.4.0_bb0868973057e0c4594582a2b34966b1571b4498-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-internal_impl-23.4.0_0380fc8cb59e96244f130184574ead0ab4fa81a6-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.4.0_222d58f6b3309dd767eaedd78b101df07bb0214b-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-support-v4-23.4.0_d9254cdfbfc7a83fc69750e7bacf0c28659d5fbe-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-design-23.0.1_e104774034c64e7848d1f2ca9937e0b0ba73cbda-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.4.0_9c2b828fb5b4db0ad04d9c69d99c765617e6767c-classes.dex", dex 
      06-23 11:23:05.950 21271-21271/com.example.cortana.testing D/Error: ERR: exClass=java.lang.ClassNotFoundException
      06-23 11:23:05.950 21271-21271/com.example.cortana.testing D/Error: ERR: exMsg=Didn't find class "android.support.v7.internal.widget.TintManager" on path: DexPathList[[dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-support-annotations-23.4.0_bb0868973057e0c4594582a2b34966b1571b4498-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-internal_impl-23.4.0_0380fc8cb59e96244f130184574ead0ab4fa81a6-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.4.0_222d58f6b3309dd767eaedd78b101df07bb0214b-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-support-v4-23.4.0_d9254cdfbfc7a83fc69750e7bacf0c28659d5fbe-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-design-23.0.1_e104774034c64e7848d1f2ca9937e0b0ba73cbda-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.4.0_9c2b828fb5b4db0ad04d9c69d99c765617e6767c-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.4.0_295f5bae1ae17fe25c8f6037cf5499452801adbf-classes.dex"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64, /vendor/lib64, /system/lib64]]
      06-23 11:23:05.950 21271-21271/com.example.cortana.testing D/Error: ERR: file=BaseDexClassLoader.java
      06-23 11:23:05.950 21271-21271/com.example.cortana.testing D/Error: ERR: class=dalvik.system.BaseDexClassLoader
      06-23 11:23:05.950 21271-21271/com.example.cortana.testing D/Error: ERR: method=findClass line=56
      06-23 11:23:05.951 21271-21271/com.example.cortana.testing D/Error: ERR: stack=java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/internal/widget/TintManager;
  at android.support.design.widget.TabLayout$TabView.&lt;init&gt;(TabLayout.java:1145)
  at android.support.design.widget.TabLayout.createTabView(TabLayout.java:635)
  at android.support.design.widget.TabLayout.addTabView(TabLayout.java:669)
  at android.support.design.widget.TabLayout.addTab(TabLayout.java:365)
  at android.support.design.widget.TabLayout.addTab(TabLayout.java:340)
  at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:624)
  at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:595)
  at com.example.cortana.testing.activity.MainActivity$override.onCreate(MainActivity.java:44)
  at com.example.cortana.testing.activity.MainActivity$override.access$dispatch(MainActivity.java)
  at com.example.cortana.testing.activity.MainActivity.onCreate(MainActivity.java:0)
  at android.app.Activity.performCreate(Activity.java:6220)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2646)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4324)
  at android.app.ActivityThread.access$900(ActivityThread.java:182)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
  at android.os.Handler.dispatchMessage(Handler.java:111)
  at android.os.Looper.loop(Looper.java:194)
  at android.app.ActivityThread.main(ActivityThread.java:5763)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
  Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.widget.TintManager" on path: DexPathList[[dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-support-annotations-23.4.0_bb0868973057e0c4594582a2b34966b1571b4498-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-internal_impl-23.4.0_0380fc8cb59e96244f130184574ead0ab4fa81a6-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.4.0_222d58f6b3309dd767eaedd78b101df07bb0214b-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-support-v4-23.4.0_d9254cdfbfc7a83fc69750e7bacf0c28659d5fbe-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-design-23.0.1_e104774034c64e7848d1f2ca9937e0b0ba73cbda-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.4.0_9c2b828fb5b4db0ad04d9c69d99c765617e6767c-classes.dex", dex file "/data/data/com.example.cortana.testing/files/instant-run/dex/sl
  06-23 11:23:05.951 21271-21271/com.example.cortana.testing D/Error: ERR: TOTAL BYTES WRITTEN: 21616
  06-23 11:23:07.877 21271-21271/com.example.cortana.testing I/Process: Sending signal. PID: 21271 SIG: 9
  </code></pre>
  
  <p>I dont know why this is happening. What should I do to resolve it? Also please include the reason of this crash. </p>
  
  <p>Edit: I have included the library <code>compile com.android.support:design:23.1.1'</code> in the build.gradle but its still giving the exact same error. I have cleaned the project and then rebuilt it. 
  The build.gradle looks like this:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
  
      defaultConfig {
          applicationId "com.example.cortana.testing"
          minSdkVersion 15
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.4.0'
      compile 'com.android.support:design:23.1.1'
  }
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>I have installed the same version of libraries and it still wont work. Can someone please suggest some other ideas. 
  As I told before, the function thats tripping everything up is <code>tablayout.setupWithViewPager(viewPager);</code>. If I comment it out, the app works fine.</p>