一切正常,直到我更新了我的gradle文件,现在我的tablayout由于错误而崩溃:
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) 在android.support.design.widget.TabLayout.addTab(TabLayout.java:386) 在android.support.design.widget.TabLayout.addTab(TabLayout.java:361) 在android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645) 在android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616) at com.example.ScrollableTabsActivity.onCreate(ScrollableTabsActivity.java:307) 在android.app.Activity.performCreate(Activity.java:6033) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2397) 在android.app.ActivityThread.access $ 800(ActivityThread.java:151) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1310) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:135) 在android.app.ActivityThread.main(ActivityThread.java:5268) at java.lang.reflect.Method.invoke(Native Method) 在java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:902) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) 引起:java.lang.ClassNotFoundException:路径上没有找到类“android.support.v7.widget.TintManager”:DexPathList [[zip file“/data/app/com.example-1/base.apk”] ,nativeLibraryDirectories = [/ vendor / lib,/ system / lib]] 在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 在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) 在android.support.design.widget.TabLayout.addTab(TabLayout.java:386) 在android.support.design.widget.TabLayout.addTab(TabLayout.java:361) 在android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645) 在android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616)
这是我的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')
}
请帮帮我错误
答案 0 :(得分:38)
更改依赖项就行了,只需将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'
我不知道为什么有些人认为我的问题是否定的,反正这可能对某人有帮助
答案 1 :(得分:9)
所有支持库必须具有相同的版本。 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"
答案 2 :(得分:-1)
首先创建一个新活动但不是空活动,然后选择标签活动,然后像我一样做..
步骤1:创建三个片段活动首先从每个片段活动中删除所有内容,然后将此代码写入每个活动
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<----
}
}
第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;
}
}
第3步:最后使用此代码更改您的sectionpageradapter函数 - &gt;
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;
}
}