-3

我正在尝试修复我的应用程序,但我无法弄清楚问题所在。只有当我在 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 中找到问题...您能找到吗?

什么是可能的解决方案?

谢谢

4

3 回答 3

0

我找到了解决方案!

我的 custom_tab.xml 是

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:textStyle="bold"
    android:background="?android:selectableItemBackground
    android:padding="16dp"
    android:gravity="center"
/>

现在是

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:textStyle="bold"
    android:background="@color/pb_blue"
    android:padding="16dp"
    android:gravity="center"
/>

现在我必须测试很多!感谢您对所有投反对票的人的所有回复和 gtfo!

再见,谢谢^^

于 2015-07-30T09:50:29.663 回答
0

我想你可能会在充气机上使用上下文

final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.myInflatedLayout, null);

而是像这样尝试

final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.myInflatedLayout, null);

从“getSystemService”中删除“this”或“context”

于 2015-07-30T08:09:30.103 回答
0

尝试将 textview id 作为此函数的第二个参数传递。slipTabLayout.setCustomTabView(R.layout.custom_tab, 0)。

于 2015-07-30T09:02:02.873 回答