Android java.lang.IllegalArgumentException:path必须是凸的

时间:2018-04-03 00:51:50

标签: android android-logcat illegalargumentexception

Android 7中的相同应用程序工作,Android 8中的失败。

在活动中,我正在从Fire-base数据库中检索数据。当Fire-base数据库为空时,没有错误发生,并且当数据有数据时发生错误,我搜索错误但从未得到任何解决方案。

logcat: -

java.lang.IllegalArgumentException: path must be convex
        at android.graphics.Outline.setConvexPath(Outline.java:284)
        at android.graphics.drawable.AdaptiveIconDrawable.getOutline(AdaptiveIconDrawable.java:387)
        at android.view.ViewOutlineProvider$1.getOutline(ViewOutlineProvider.java:38)
        at android.view.View.rebuildOutline(View.java:14960)
        at android.view.View.setBackgroundBounds(View.java:19416)
        at android.view.View.drawBackground(View.java:19381)
        at android.view.View.draw(View.java:19183)
        at android.view.View.updateDisplayListIfDirty(View.java:18142)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.draw(View.java:19195)
        at android.view.View.updateDisplayListIfDirty(View.java:18142)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:4703)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.draw(View.java:19195)
        at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:4107)
        at android.view.View.updateDisplayListIfDirty(View.java:18142)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.updateDisplayListIfDirty(View.java:18133)
        at android.view.View.draw(View.java:18920)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4236)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4022)
        at android.view.View.draw(View.java:19195)
        at com.android.internal.policy.DecorView.draw(DecorView.java:788)
        at android.view.View.updateDisplayListIfDirty(View.java:18142)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:669)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:675)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:783)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:2992)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2806)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2359)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
        at android.view.Choreographer.doCallbacks(Choreographer.java:723)

item_people.xml的代码

    

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:weightSum="1"
        android:orientation="horizontal">

        <de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/icon_avata"
            android:layout_width="0dp"
            android:layout_weight="0.15"
            android:layout_height="50dp"
            android:layout_margin="10dp"
            android:background="@mipmap/ic_launcher_round"
            app:civ_border_color="@color/colorPrimary" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:layout_weight="0.8"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            tools:ignore="RtlHardcoded">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingTop="5dp">

                <TextView
                    android:id="@+id/people_name"
                    android:layout_width="0dp"
                    android:text="link"
                    android:layout_height="match_parent"
                    android:layout_weight="0.7"
                    android:gravity="center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/txtTime"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.3"
                    android:text=""
                    android:gravity="center_vertical|right"
                    android:paddingRight="10dp"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    tools:ignore="RtlHardcoded,RtlSymmetry" />
            </LinearLayout>

            <TextView
                android:id="@+id/txtNickname"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="name"
                android:ellipsize="end"
                android:gravity="center_vertical"
                android:lines="1"
                android:paddingBottom="10dp"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

2 个答案:

答案 0 :(得分:5)

查看堆栈跟踪,前几行说明了一个故事:

java.lang.IllegalArgumentException: path must be convex
        at android.graphics.Outline.setConvexPath(Outline.java:284)
        at android.graphics.drawable.AdaptiveIconDrawable.getOutline(AdaptiveIconDrawable.java:387)
        at android.view.ViewOutlineProvider$1.getOutline(ViewOutlineProvider.java:38)
        at android.view.View.rebuildOutline(View.java:14960)
        at android.view.View.setBackgroundBounds(View.java:19416)
        at android.view.View.drawBackground(View.java:19381)
  • 第3行提及AdaptiveIconDrawable
  • 第7行提及View.drawBackground()

搜索AdaptiveIconDrawable告诉我们这是一个新的Android 8功能:

这解释了为什么你的代码在Android 7上有效但在8上崩溃。在Android 7上,系统不使用自适应图标,而是使用普通的PNG。在Android 8上,如果您提供了自适应图标,它将使用自适应图标。

新图标似乎有问题,或者只是在您使用它的地方不起作用。

接下来我们需要了解背景是什么......

查看您的CardView布局,即可将您的启动器图标(在Android 8上,这可能是您的AdaptiveIconDrawable)设置到CircleImageView背景上。

这就是发生崩溃的地方 - 图标无效,或CircleImageView以这种方式使用时不支持它。

修复方法是在您的应用中包含一个PNG图标,在这种情况下将作为背景。

答案 1 :(得分:1)

假设您的图标设置正确,请尝试使用table(i,j)而非android:src为CircleImageView设置图标。