致命exception:main java.lang.NoClassDefFoundError:android.support.v7.internal.widget.TintManager

我在运行我的项目时遇到错误。 我只是按照这个教程 ,并在我的项目中使用它。

我的代码在教程中完全一样

public class MainEventActivity extends AppCompatActivity { private Toolbar toolbar; private TabLayout tabLayout; private ViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_event_activity); 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 OneFragment(), "ONE"); adapter.addFragment(new TwoFragment(), "TWO"); adapter.addFragment(new ThreeFragment(), "THREE"); viewPager.setAdapter(adapter); } class ViewPagerAdapter extends FragmentPagerAdapter { private final List<Fragment> mFragmentList = new ArrayList<>(); private final List<String> mFragmentTitleList = new ArrayList<>(); 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); } } 

我像这样调用MainEventActivity:

 btnNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(MainActivity.this, MainEventActivity.class); startActivity(i); finish(); } }); 

我的错误日志:

 12-01 08:00:29.903 22530-22530/com.erlawkward.albarol.eventlocatorapp E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NoClassDefFoundError: android.support.v7.internal.widget.TintManager at android.support.design.widget.TabLayout$TabView.<init>(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.erlawkward.albarol.eventlocatorapp.activity.activity.MainEventActivity.onCreate(MainEventActivity.java:41) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) 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:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) 

错误在这一行:

  tabLayout.setupWithViewPager(viewPager); 

所有的支持库必须是相同的版本。 尝试将appcompat-v7和support-v4更改为23.0.1或devise为23.1.1

如果您下载更高版本的支持库,即使您定义为23.1.1 ,gradle也会默认使用较高版本。

您可以检查gradlew app:dependencies -q是否使用正确的版本。

要修复它的高版本切换,请对以下所有支持库设置force = true

 compile ('com.android.support:support-v4:23.1.1'){ force = true; } compile ('com.android.support:appcompat-v7:23.1.1'){ force = true; } compile ('com.android.support:design:23.1.1'){ force = true; } compile ('com.android.support:cardview-v7:23.1.1'){ force = true; } compile ('com.android.support:recyclerview-v7:23.1.1'){ force = true; } 

我修改了一个类似的问题,通过改变我的依赖从:

编译“com.android.support:design:23.1.1”

编译'com.android.support:design:23.+'

最后我的单位是这样的:

 compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:support-v4:23.0.0' compile 'com.android.support:cardview-v7:23.0.0' compile 'com.android.support:design:23.+' 

我认为这是因为你的gradle中使用了lib的“compile”com.mcxiaoke.volley:library-aaa:1.0.0“”,包括你的gradle中定义的不同版本的“com.android.support :: ”。

所以你应该这样做:

 compile ('com.mcxiaoke.volley:library-aaa:1.0.0') { transitive = false } 

我通过添加编译“com.android.support:design:23.+”来解决这个问题,尽pipe我的支持依赖类似

之前

  compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:design:23.1.1' 

之后 – 这对我有用

  compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:design:23.+' 
 compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:design:23.4.0' 

您必须像上面一样使用相同的版本来进行依赖

试着用相同的版本来设置所有的支持库

 compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:design:23.1.1' 

似乎他们用AppCompatDrawableManagerreplace了TintManager。

至less我确保我在任何地方都使用了相同的支持库版本(24.0.0),直到我replace了所有的TintManager与AppCompatDrawableManager一起使用的地方,它依然不起作用。

而这里 AppCompatDrawableManager仍然标记着TintManager。

compile'c​​om.android.support:appcompat-v7:23.2.0'compile'c​​om.android.support:design:23.2.0'compile'c​​om.android.support:recyclerview-v7:23.2.0'compile'c​​om。 android.support:support-v4:23.2.0'compile'c​​om.android.support:cardview-v7:23.2.0'