FATAL EXCEPTION: main java.lang.NoClassDefFoundErr

2019-02-05 11:34发布

问题:

I'm getting an error when I'm running my project. I was just following this tutorial and used it in my project.

my code which is exactly alike in the tutorial

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);
    }
}

Im calling the MainEventActivity like this :

btnNext.setOnClickListener(new View.OnClickListener() {

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

my error log:

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)

error in this line:

    tabLayout.setupWithViewPager(viewPager);

回答1:

All the support libraries have to be the same version. Try changing either appcompat-v7 and support-v4 to 23.0.1 or design to 23.1.1



回答2:

If you download higher version of support library, gradle uses upper version silently even if you defined as 23.1.1.

You can check gradlew app:dependencies -q whether correct version is used or not.

To fix its upper version handover, set force = true to all of support libraries as below.

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;
}


回答3:

I fixed a similar issue by changing my dependence from:

compile 'com.android.support:design:23.1.1'

to

compile 'com.android.support:design:23.+'

My units at the end were in this way:

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.+'


回答4:

I think that is because the lib "compile 'com.mcxiaoke.volley:library-aaa:1.0.0' " used in your gradle including the different version of 'com.android.support::' as define in your gradle.

so you should do it like:

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


回答5:

I solved this issues by adding compile 'com.android.support:design:23.+' though my supporting dependencies are similar

Before

   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'

After - this works for me

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


回答6:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'

You must use same version for dependency like above



回答7:

try with set all support lib with same verion for example

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'


回答8:

Seems that they have replaced TintManager with AppCompatDrawableManager.

At least I made sure that I've used everywhere the same support library version (24.0.0) and it still didn't work until I just replaced all the places were TintManager was used with AppCompatDrawableManager.

And here AppCompatDrawableManager has still tag TintManager.



回答9:

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