我正在尝试修复我的应用程序,但我无法弄清楚问题所在。只有当我在 Android 版本 < 4.0 上运行应用程序时才会出现问题,所以我猜问题出在 appcompat 上,但我不知道如何解决。我运行它时的错误是这样的:
07-30 09:40:44.726 14081-14081/my.app.pag E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app.pag/my.app.pag.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at my.app.pag.utils.SlidingTabLayout.populateTabStrip(SlidingTabLayout.java:207)
at my.app.pag.utils.SlidingTabLayout.setViewPager(SlidingTabLayout.java:166)
at my.app.pag.fragment.MainFragment.onCreateView(MainFragment.java:96)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
at it.seatpg.core.activity.CoreActivity.onStart(CoreActivity.java:119)
at my.app.pag.MainActivity.onStart(MainActivity.java:469)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3791)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x101030e a=-1}
at android.content.res.Resources.loadDrawable(Resources.java:1681)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1961)
at android.widget.TextView.<init>(TextView.java:376)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:44)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:40)
at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832)
at android.support.v4.view.LayoutInflaterCompatBase$FactoryWrapper.onCreateView(LayoutInflaterCompatBase.java:36)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at my.app.pag.utils.SlidingTabLayout.populateTabStrip(SlidingTabLayout.java:207)
at my.app.pag.utils.SlidingTabLayout.setViewPager(SlidingTabLayout.java:166)
at my.app.pag.fragment.MainFragment.onCreateView(MainFragment.java:96)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
at my.app.core.activity.CoreActivity.onStart(CoreActivity.java:119)
at my.app.pag.MainActivity.onStart(MainActivity.java:469)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3791)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
我的片段中的代码(在 onCreateView 中)是这样的:
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_main,
container, false);
ViewPager pager = (ViewPager) root.findViewById(R.id.pager);
FragmentManager fm = getChildFragmentManager();
MainPagerAdapter adapter = new MainPagerAdapter(fm, getActivity(),
recentWhere, recentWhat);
pager.setAdapter(adapter);
// pager.setOffscreenPageLimit(2);
// pager.setCurrentItem(page);
SlidingTabLayout slidingTabLayout = (SlidingTabLayout) root
.findViewById(R.id.sliding_tabs);
slidingTabLayout.setCustomTabView(R.layout.custom_tab, 0);
slidingTabLayout.setBackgroundColor(getResources().getColor(R.color.pb_blue));
slidingTabLayout.setDistributeEvenly(true);
slidingTabLayout.setViewPager(pager);
slidingTabLayout
.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.pb_white);
}
});
我的 gradle 版本是这样的:
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'
compile 'io.gsonfire:gson-fire:1.0.1'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile files('libs/cardview-v7.jar')
compile files('libs/core-2.13.42.jar')
compile files('libs/recyclerview-v7.jar')
compile files('libs/simple-xml-2.7.jar')
compile files('libs/universal-image-loader-1.9.1.jar')
compile files('libs/GoogleConversionTrackingSdk-2.2.2.jar')
compile project(':adobeMobileLibrary-4.4.1')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/adagiosdk_2.6.1.jar')
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:design:22.2.0'
}
这是片段的xml
<my.app.pag.slideup.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:shadowHeight="4dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<my.app.pag.utils.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</LinearLayout>
<LinearLayout
android:id="@+id/grid_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp" >
<GridView
android:id="@+id/grid_view_services"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:choiceMode="singleChoice"
android:gravity="center"
android:numColumns="3"
android:stretchMode="columnWidth" />
</LinearLayout>
</my.app.pag.slideup.SlidingUpPanelLayout>
我没有在错误日志中打印的 xml 中找到问题...您能找到吗?
什么是可能的解决方案?
谢谢