在4.4.2上填写类TextView时出错

时间:2017-09-07 05:49:47

标签: android

Fatal Exception: android.view.InflateException: Binary XML file line #33: Error inflating class TextView at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714) at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at wscconnect.android.adapters.AppAdapter.onCreateViewHolder(SourceFile:70) at wscconnect.android.adapters.AppAdapter.onBindViewHolder(SourceFile:56) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(SourceFile:6487) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(SourceFile:5674) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(SourceFile:5557) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(SourceFile:5553) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(SourceFile:2229) at android.support.v7.widget.GridLayoutManager.layoutChunk(SourceFile:556) at android.support.v7.widget.LinearLayoutManager.fill(SourceFile:1516) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(SourceFile:608) at android.support.v7.widget.GridLayoutManager.onLayoutChildren(SourceFile:170) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(SourceFile:3693) at android.support.v7.widget.RecyclerView.dispatchLayout(SourceFile:3410) at android.support.v7.widget.RecyclerView.onLayout(SourceFile:3962) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.support.v4.widget.SwipeRefreshLayout.onLayout(SourceFile:610) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.support.v7.widget.ActionBarOverlayLayout.onLayout(SourceFile:443) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5021) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(NativeStart.java) Caused by android.content.res.Resources$NotFoundException: File res/drawable/ic_notifications_white_12dp.xml from drawable resource ID #0x7f020064 at android.content.res.Resources.loadDrawable(Resources.java:2101) at android.content.res.TypedArray.getDrawable(TypedArray.java:602) at android.widget.TextView.(TextView.java) at android.support.v7.widget.AppCompatTextView.(SourceFile) at android.support.v7.widget.AppCompatTextView.(SourceFile) at android.support.v7.app.AppCompatViewInflater.createView(SourceFile:103) at android.support.v7.app.AppCompatDelegateImplV9.createView(SourceFile:1024) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(SourceFile:1081) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at wscconnect.android.adapters.AppAdapter.onCreateViewHolder(SourceFile:70) at wscconnect.android.adapters.AppAdapter.onBindViewHolder(SourceFile:56) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(SourceFile:6487) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(SourceFile:5674) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(SourceFile:5557) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(SourceFile:5553) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(SourceFile:2229) at android.support.v7.widget.GridLayoutManager.layoutChunk(SourceFile:556) at android.support.v7.widget.LinearLayoutManager.fill(SourceFile:1516) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(SourceFile:608) at android.support.v7.widget.GridLayoutManager.onLayoutChildren(SourceFile:170) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(SourceFile:3693) at android.support.v7.widget.RecyclerView.dispatchLayout(SourceFile:3410) at android.support.v7.widget.RecyclerView.onLayout(SourceFile:3962) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.support.v4.widget.SwipeRefreshLayout.onLayout(SourceFile:610) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.support.v7.widget.ActionBarOverlayLayout.onLayout(SourceFile:443) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5021) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(NativeStart.java) Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877) at android.content.res.Resources.loadDrawable(Resources.java:2097) at android.content.res.TypedArray.getDrawable(TypedArray.java:602) at android.widget.TextView.(TextView.java) at android.support.v7.widget.AppCompatTextView.(SourceFile) at android.support.v7.widget.AppCompatTextView.(SourceFile) at android.support.v7.app.AppCompatViewInflater.createView(SourceFile:103) at android.support.v7.app.AppCompatDelegateImplV9.createView(SourceFile:1024) at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(SourceFile:1081) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at wscconnect.android.adapters.AppAdapter.onCreateViewHolder(SourceFile:70) at wscconnect.android.adapters.AppAdapter.onBindViewHolder(SourceFile:56) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(SourceFile:6487) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(SourceFile:5674) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(SourceFile:5557) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(SourceFile:5553) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(SourceFile:2229) at android.support.v7.widget.GridLayoutManager.layoutChunk(SourceFile:556) at android.support.v7.widget.LinearLayoutManager.fill(SourceFile:1516) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(SourceFile:608) at android.support.v7.widget.GridLayoutManager.onLayoutChildren(SourceFile:170) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(SourceFile:3693) at android.support.v7.widget.RecyclerView.dispatchLayout(SourceFile:3410) at android.support.v7.widget.RecyclerView.onLayout(SourceFile:3962) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.support.v4.widget.SwipeRefreshLayout.onLayout(SourceFile:610) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.support.v7.widget.ActionBarOverlayLayout.onLayout(SourceFile:443) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14817) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5021) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(NativeStart.java)

在Android 4.4.2的这一行中出现 - 它在其他几个版本中运行良好:

View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_app, parent, false);

我的布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">

    <android.support.v7.widget.CardView
        android:id="@+id/card_challenge_card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        card_view:cardElevation="0dp"
        card_view:cardMaxElevation="0dp"
        card_view:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#f6f6f6">

            <FrameLayout
                android:id="@+id/card_challenge_cover_container"
                android:layout_width="match_parent"
                android:layout_height="70dp">

                <ImageView
                    android:id="@+id/list_app_logo"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:scaleType="centerCrop" />

                <TextView
                    android:id="@+id/list_app_unread_notifications"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/badge"
                    android:textColor="#ffffff"
                    android:textSize="10sp"
                    android:drawablePadding="2dp"
                    android:drawableStart="@drawable/ic_notifications_white_12dp"
                    android:layout_gravity="bottom|start"
                    android:layout_marginBottom="3dp"
                    android:layout_marginStart="3dp"
                    android:visibility="gone" />

                <TextView
                    android:id="@+id/list_app_users"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawablePadding="2dp"
                    android:drawableStart="@drawable/ic_people_white_12dp"
                    android:textColor="#ffffff"
                    android:layout_gravity="bottom|end"
                    android:layout_marginBottom="3dp"
                    android:layout_marginEnd="3dp"
                    android:background="@drawable/badge_primary"
                    android:textSize="10sp" />
            </FrameLayout>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/card_challenge_cover_container"
                android:padding="5dp">

                <TextView
                    android:id="@+id/list_app_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:ellipsize="end"
                    android:maxLines="2"
                    android:textSize="11sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/list_app_url"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/list_app_name"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:textSize="11sp" />
            </RelativeLayout>
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

3 个答案:

答案 0 :(得分:4)

当使用支持库时,可绘制的载体通常用于棒棒糖前设备。 不知何故,它们不适用于drawableStartdrawableEnd等属性。

我替换了我的

       <TextView
                android:id="@+id/list_app_users"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawablePadding="2dp"
                android:drawableStart="@drawable/ic_people_white_12dp"
                android:textColor="#ffffff"
                android:layout_gravity="bottom|end"
                android:layout_marginBottom="3dp"
                android:layout_marginEnd="3dp"
                android:background="@drawable/badge_primary"
                android:textSize="10sp" />

布局略微复杂,适用于所有设备:

            <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/list_app_users_container"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_marginBottom="3dp"
                android:layout_marginEnd="3dp"
                android:background="@drawable/badge_primary">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="3dp"
                    app:srcCompat="@drawable/ic_people_white_12dp" />

                <TextView
                    android:id="@+id/list_app_users"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#ffffff"
                    android:textSize="10sp" />

            </LinearLayout>

答案 1 :(得分:0)

您的项目中不存在此文件res / drawable / ic_notifications_white_12dp.xml

所以你必须删除这一行

                    android:drawableStart="@drawable/ic_notifications_white_12dp"

希望这会对你有所帮助。

答案 2 :(得分:-1)

LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_app, parent, false);