android.view.InflateException:二进制 XML 文件第 133 行:错误膨胀类 <unknown>

时间:2021-06-14 16:12:37

标签: android xml android-layout android-fragments

我正在尝试启动此片段,但出现以下错误。从我读到的内容来看,这似乎有一个可能的大图像,但我没有识别它,毕竟在这部分中它称为地图。如果有人遇到过这个错误,我很感激贡献!`

2021-06-14 12:42:10.327 26833-26833/com.helpcars.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.helpcars.app, PID: 26833
    android.view.InflateException: Binary XML file line #133: Binary XML file line #133: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #133: Error inflating class <unknown>
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at com.helpcars.app.Fragments.HomeFragment.onCreateView(HomeFragment.java:308)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
        at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: android.content.res.Resources$NotFoundException: Drawable android:color/primary_text_dark with resource ID #0x1060001
     Caused by: android.content.res.Resources$NotFoundException: File res/color/primary_text_dark.xml from drawable resource ID #0x1060001
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:847)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:631)
        at android.content.res.Resources.loadDrawable(Resources.java:897)
        at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:955)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
        at android.view.View.<init>(View.java:5010)
        at android.view.ViewGroup.<init>(ViewGroup.java:659)
        at android.widget.LinearLayout.<init>(LinearLayout.java:244)
        at android.widget.LinearLayout.<init>(LinearLayout.java:240)
        at android.widget.LinearLayout.<init>(LinearLayout.java:236)
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
2021-06-14 12:42:10.331 26833-26833/com.helpcars.app E/AndroidRuntime:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at com.helpcars.app.Fragments.HomeFragment.onCreateView(HomeFragment.java:308)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
        at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: <item> tag requires a 'drawable' attribute or child tag defining a drawable
        at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:190)
        at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:122)
        at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
        at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1332)
        at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1291)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:833)
            ... 42 more

这是我试图“膨胀”的布局的 XML。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- Map frame -->

        <LinearLayout
            android:id="@+id/mapLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <fragment xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/provider_map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>


        <!--Project Flow-->


                <!--Request to providers-->
                <LinearLayout
                    android:id="@+id/lnrRequestProviders"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:background="@android:color/white"
                    android:orientation="vertical"
                    android:visibility="gone">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">


                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/rcvServiceTypes"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="@dimen/_5sdp"
                            android:layout_marginTop="@dimen/_5sdp" />

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:background="@color/view_bg" />


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/_10sdp"
                            android:gravity="center_vertical"
                            android:orientation="horizontal">

                            <ImageView
                                android:id="@+id/imgPaymentType"
                                android:layout_width="@dimen/_20sdp"
                                android:layout_height="@dimen/_20sdp"
                                app:srcCompat="@drawable/money1" />

                            <com.helpcars.app.Utils.MyBoldTextView
                                android:id="@+id/lblPaymentType"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="10dp"
                                android:layout_weight="1"
                                android:text="@string/selected_payment_mode"
                                android:textColor="@android:color/black"
                                android:textSize="16sp" />

                            <com.helpcars.app.Utils.MyBoldTextView
                                android:id="@+id/lblPaymentChange"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:gravity="right"
                                android:text="@string/change"
                                android:textColor="@android:color/holo_blue_dark"
                                android:textSize="16sp" />

                        </LinearLayout>

                    </LinearLayout>

                    <com.helpcars.app.Utils.MyButton
                        android:id="@+id/btnRequestRides"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="@dimen/_10sdp"
                        android:layout_marginLeft="@dimen/_20sdp"
                        android:layout_marginRight="@dimen/_20sdp"
                        android:layout_marginTop="@dimen/_10sdp"
                        android:background="@drawable/rounded_button"
                        android:text="@string/estimate"
                        android:textColor="@color/button_text_color" />


                </LinearLayout>

                <!-- Provider popup Layout-->
                <LinearLayout
                    android:id="@+id/lnrProviderPopup"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:orientation="vertical"
                    android:visibility="gone">

                    <LinearLayout
                        android:id="@+id/lnrHidePopup"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:background="@color/transparent_black"
                        android:orientation="vertical"
                        android:visibility="gone">

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom"
                        android:background="@android:color/primary_text_dark"
                        android:gravity="center"
                        android:orientation="vertical"
                        android:padding="@dimen/_10sdp">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/imgProviderPopup"
                            android:layout_width="@dimen/_60sdp"
                            android:layout_height="@dimen/_60sdp"
                            android:layout_marginTop="@dimen/_5sdp"
                            android:src="@drawable/pickup_drop_icon" />

                        <com.helpcars.app.Utils.MyBoldTextView
                            android:id="@+id/lblServiceName"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginTop="@dimen/_10sdp"
                            android:gravity="center"
                            android:maxLines="1"
                            android:text=""
                            android:textColor="@color/text_color_black"
                            android:textSize="@dimen/_14sdp" />

                        <com.helpcars.app.Utils.MyBoldTextView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginTop="@dimen/_5sdp"
                            android:gravity="center"
                            android:maxLines="1"
                            android:text="Aguarde o reboque em um local seguro"
                            android:textColor="@color/text_color_black"
                            android:textSize="@dimen/_14sdp" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="bottom"
                            android:layout_marginTop="@dimen/_10sdp"
                            android:background="@android:color/primary_text_dark"
                            android:gravity="center"
                            android:orientation="vertical">

                            <LinearLayout
                                android:id="@+id/lnrPriceBase"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="start"
                                    android:maxLines="1"
                                    android:text="Base Price"
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:id="@+id/lblBasePricePopup"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="end"
                                    android:maxLines="1"
                                    android:text=""
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />
                            </LinearLayout>

                            <LinearLayout
                                android:id="@+id/lnrPricekm"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/_5sdp"
                                android:orientation="horizontal">

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="start|center"
                                    android:maxLines="1"
                                    android:text="Price/km"
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:id="@+id/lblPriceKm"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="end"
                                    android:maxLines="1"
                                    android:text=""
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />
                            </LinearLayout>

                            <LinearLayout
                                android:id="@+id/lnrPricemin"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/_5sdp"
                                android:orientation="horizontal">

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="start|center"
                                    android:maxLines="1"
                                    android:text="Price/min"
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:id="@+id/lblPriceMin"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="end"
                                    android:maxLines="1"
                                    android:text=""
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />
                            </LinearLayout>

                            <LinearLayout
                                android:id="@+id/lnrCalculationType"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/_5sdp"
                                android:orientation="horizontal">

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="start|center"
                                    android:maxLines="1"
                                    android:text="- É obrigatório o acompanhamento do responsável"
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />
                            </LinearLayout>

                            <LinearLayout
                                android:id="@+id/lnrCapacity"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/_5sdp"
                                android:orientation="horizontal">

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="start|center"
                                    android:maxLines="1"
                                    android:text="- Para remoção, somente veículos descarregados"
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />

                                <com.helpcars.app.Utils.MyBoldTextView
                                    android:id="@+id/lblCapacity"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:layout_weight="1"
                                    android:gravity="end"
                                    android:maxLines="1"
                                    android:text=""
                                    android:textColor="@color/black_text_color"
                                    android:textSize="@dimen/_12sdp" />
                            </LinearLayout>

                        </LinearLayout>

                        <com.helpcars.app.Utils.MyBoldTextView
                            android:id="@+id/lblProviderDesc"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginTop="@dimen/_15sdp"
                            android:layout_weight="1"
                            android:lineSpacingMultiplier="1.3"
                            android:text="The fare will be the price presented upon booking, or, if the journey changes, the fare will be based on the rates provided. Tap fare for details."
                            android:textSize="@dimen/_10sdp" />
                    </LinearLayout> 

首页片段


   @Override
    public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_home, container, false);
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                init(rootView);
                //permission to access location
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    // Android M Permission check
                    requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
                } else {
                    initMap();
                    MapsInitializer.initialize(getActivity());
                }
            }
        }, 500);
        return rootView;
    }

细节是它适用于各种设备和安卓版本,但特别是对于 Moto G Android Pie,我收到了这个错误。

错误在 XML 文件第 133 行,但我不明白为什么 LinearLayout 从那里开始。

1 个答案:

答案 0 :(得分:0)

基于提供的源代码的可能解决方案:

  1. 检查您是否使用 android:src 而不是 app:srcCompat 来分配矢量资源。 @drawable/pickup_drop_icon 是矢量资产吗?如果是,则不应使用 android:src

  2. 您忘记放置父项的尾随 </LinearLayout>。 将 </LinearLayout> 添加到代码底部。 尝试对 XML 文件进行代码折叠,您会注意到它末尾缺少 </LinearLayout>。 当编译器给出一般错误消息 Binary XML file line #133: Error inflating class 时,我建议您首先确定 XML 文件中是否有任何错误。

如果您有任何问题,请告诉我。