错误:java.lang.NoClassDefFoundError Android

我正在按照本教程创build滑动选项卡 。 但是我得到了上面的错误。

我的gradle依赖关系sturucture

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:22.2.0' } 

这是我的文件。 MainActivity.java

 import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); //this line gives error tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); //this line gives error tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); PageAdapter pageAdapter = new PageAdapter(getSupportFragmentManager()); viewPager.setAdapter(pageAdapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); } } 

而我的PageAdapter.java文件是

 import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; public class PageAdapter extends FragmentStatePagerAdapter { public PageAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { switch (position) { case 0: return new InstaPicSwipeTab(); case 1: return new SongsDownloadSwipeTab(); } return null; } @Override public int getCount() { return 2; } } 

这就是LogCat给我的

 12-08 00:27:24.452 11770-11770/com.example.suraj.freewee E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.suraj.freewee, PID: 11770 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/internal/widget/TintManager; at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1041) at android.support.design.widget.TabLayout.createTabView(TabLayout.java:582) at android.support.design.widget.TabLayout.addTabView(TabLayout.java:616) at android.support.design.widget.TabLayout.addTab(TabLayout.java:334) at android.support.design.widget.TabLayout.addTab(TabLayout.java:309) at com.example.suraj.freewee.MainActivity.onCreate(MainActivity.java:23) 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) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.widget.TintManager" on path: DexPathList[[zip file "/data/app/com.example.suraj.freewee-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.suraj.freewee-1/lib/x86, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1041) at android.support.design.widget.TabLayout.createTabView(TabLayout.java:582) at android.support.design.widget.TabLayout.addTabView(TabLayout.java:616) at android.support.design.widget.TabLayout.addTab(TabLayout.java:334) at android.support.design.widget.TabLayout.addTab(TabLayout.java:309) at com.example.suraj.freewee.MainActivity.onCreate(MainActivity.java:23) 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) Suppressed: java.lang.ClassNotFoundException: android.support.v7.internal.widget.TintManager at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 19 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available 

如何解决这个错误?

Solutions Collecting From Web of "错误:java.lang.NoClassDefFoundError Android"

支持库和devise库的版本应该是一样的。

我改变了我的

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

 compile 'com.android.support:appcompat-v7:23.0.1' 

并为我解决问题。

注意 :我的compileSdkVersion和buildToolVersion下面是compileSdkVersion 23 buildToolsVersion“23.0.1”

这出现了当一个类在编译时存在,但不是在运行时,右键单击appopen module settingsselectdependencies点击+并select“库依赖”selectdesign ,然后单击ok ,等待gradle运行,重新运行你的应用程序,我确定会修复它。

你的顶级gradle将需要像这样

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion '23.0.2' defaultConfig { applicationId "aubry.chromio.com.dressup" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.java']) compile fileTree(dir: 'libs', include: ['*.so']) compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:design:23.1.0' } 

您必须导入相同的appcompat和devise库以及12.2.0版本。

我通过导入这些库来修复它。

 compile 'com.android.support:appcompat-v7:25.2.0' compile 'com.android.support:design:25.2.0' compile 'com.android.support:recyclerview-v7:25.2.0' compile 'com.android.support:support-v4:25.2.0' compile 'com.android.support:cardview-v7:25.2.0' 

你只需要添加:compile'c​​om.android.support:design:22.2.0'或者高版本:compile'c​​om.android.support:design:25.0.0'是很好的。

支持:devise包含支持:appcompat。