java 将支持库更新到 23.2.1 后 TabLayout 崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36079440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TabLayout crashing after updating support library to 23.2.1
提问by asish rauto
Everything was working fine until i updated my gradle file and now my tablayout is crashing due to error:
一切正常,直到我更新了 gradle 文件,现在我的 tablayout 由于错误而崩溃:
Java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/TintManager; at android.support.design.widget.TabLayout$TabView.(TabLayout.java:1185) at android.support.design.widget.TabLayout.createTabView(TabLayout.java:656) at android.support.design.widget.TabLayout.addTabView(TabLayout.java:695) at android.support.design.widget.TabLayout.addTab(TabLayout.java:386) at android.support.design.widget.TabLayout.addTab(TabLayout.java:361) at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645) at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616) at com.example.ScrollableTabsActivity.onCreate(ScrollableTabsActivity.java:307) at android.app.Activity.performCreate(Activity.java:6033) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2397) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5268) 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:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.TintManager" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/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:1185) at android.support.design.widget.TabLayout.createTabView(TabLayout.java:656) at android.support.design.widget.TabLayout.addTabView(TabLayout.java:695) at android.support.design.widget.TabLayout.addTab(TabLayout.java:386) at android.support.design.widget.TabLayout.addTab(TabLayout.java:361) at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645) at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616)
Java.lang.NoClassDefFoundError:解析失败:Landroid/support/v7/widget/TintManager;在 android.support.design.widget.TabLayout$TabView.(TabLayout.java:1185) 在 android.support.design.widget.TabLayout.createTabView(TabLayout.java:656) 在 android.support.design.widget.TabLayout。 addTabView(TabLayout.java:695) at android.support.design.widget.TabLayout.addTab(TabLayout.java:386) at android.support.design.widget.TabLayout.addTab(TabLayout.java:361) at android.support .design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645) 在 android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616) 在 com.example.ScrollableTabsActivity.onCreate(ScrollableTabsActivity.java:307) 在android.app.Activity.performCreate(Activity.java:6033) 在 android.app.Instrumentation。
?
?
Here is my gradle
file
这是我的gradle
文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example"
minSdkVersion 11
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.2.1'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.mcxiaoke.volley:library:1.0.+@aar'
compile 'com.github.hotchemi:stringpicker:0.0.2'
compile files('libs/devsmartlib.jar')
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile project(':lib')
}
Please help me where am wrong
请帮助我哪里错了
回答by asish rauto
changing dependencies did the trick , just added com.android.support:support-v4:23.2.0 and updated build tools version to 23.0.2
更改依赖项成功了,只是添加了 com.android.support:support-v4:23.2.0 并将构建工具版本更新为 23.0.2
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'
I dont know why some people marked my question as negative, anyways this might help someone
我不知道为什么有些人将我的问题标记为否定,无论如何这可能会帮助某人
回答by Eugen Pechanec
All support libs must have the same version. 23.2.1 or 23.1.1 or whatever but you can't mix versions.
所有支持库必须具有相同的版本。23.2.1 或 23.1.1 或其他任何版本,但您不能混合版本。
ext.supportLibVersion = "23.2.1"
// design includes recyclerview-v7 and appcompat-v7, which includes support-v4
compile "com.android.support:design:$supportLibVersion"
compile "com.android.support:cardview-v7:$supportLibVersion"
回答by snehasish
You first create a new activity but not empty activity and choose tabed activity ,then do as I did..
您首先创建一个新活动但不是空活动并选择选项卡活动,然后像我一样做..
step 1 : create three fragment activity first delete everything from each fragment activity and write this code to each activity
第 1 步:创建三个片段 Activity 首先从每个片段 Activity 中删除所有内容并将此代码写入每个 Activity
package com.yourpakagename.tabedactivity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class layout1 extends Fragment {
public layout1() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_layout12, container, false);
//changes in each activity-->R.layout.fragment_layout_name<----
}
}
step 2 : and finally in your tabbed activity we dont need this two functions
第 2 步:最后在您的选项卡式活动中,我们不需要这两个功能
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
step 3: and finally change your sectionpageradapter function with this code thats it -->
第 3 步:最后使用此代码更改您的 sectionpageradapter 函数,就是这样 -->
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
//delete return PlaceholderFragment.newInstance(position + 1);
switch (position)
{
case 0:
return new layout1();
case 1:
return new layout2();
case 2:
return new layout3();
default:
return new layout1();
}
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "SECTION 1";
case 1:
return "SECTION 2";
case 2:
return "SECTION 3";
}
return null;
}
}