当前位置:  开发笔记 > 编程语言 > 正文

错误:java.lang.NoClassDefFoundError Android

如何解决《错误:java.lang.NoClassDefFoundErrorAndroid》经验,为你挑选了2个好方法。

我正在按照本教程创建滑动选项卡.但我得到了上述错误.

我的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.(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.(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

如何解决这个错误?



1> Developine..:

支持库和设计库的版本应该相同.

我换了我的

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"


我可以确认appcompat-v7:23.1.1存在问题导致运行时异常`NoClassDefFoundError TintManager`的解析失败.我更新到`23.3.0`并修复了异常

2> life evader..:

当一个类在编译时存在而不是在运行时出现时,右键单击appgo以open module settings选择dependencies单击+并选择'library dependency'选择design并单击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'

}

推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有