Android java.lang.IllegalArgumentException: 路径必须是凸的
Android java.lang.IllegalArgumentException: path must be convex
相同的应用程序在 Android 7 中工作但在 Android 8 中失败。
在 activity 我正在从 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.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>
查看堆栈跟踪,前几行讲述了一个故事:
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.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 图标,在这种情况下用作背景。
假设您的图标设置正确,请尝试使用 android:src
而不是 android:background
为 CircleImageView 设置图标。
相同的应用程序在 Android 7 中工作但在 Android 8 中失败。
在 activity 我正在从 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.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>
查看堆栈跟踪,前几行讲述了一个故事:
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.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 图标,在这种情况下用作背景。
假设您的图标设置正确,请尝试使用 android:src
而不是 android:background
为 CircleImageView 设置图标。