java.lang.IllegalArgumentException:在Android OREO中的android.graphics.Outline.setConvexPath中

时间:2018-09-13 11:39:11

标签: java android

我的应用程序在playstore中有一个错误。它仅在OREO设备中发生。跟踪在下面。您能帮我找到原因吗?

D:\Trabalhos\Mobile\node\cordova>cordova -v
8.0.0

D:\Trabalhos\Mobile\node\cordova>node -v
v10.10.0

顺便说一句,我有一个下面的方法。它返回已安装应用程序的列表。列表的元素是“ MainActivity_App”。在方法中,首先,我一个接一个地获取应用程序的图标,程序包名称和名称,然后使用它们创建MainActivity_App。该代码可能会发生错误吗?

java.lang.IllegalArgumentException: 
  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.draw (View.java:19062)
  at android.view.ViewGroup.drawChild (ViewGroup.java:4236)
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4022)
  at android.view.View.draw (View.java:19060)
  at android.view.ViewGroup.drawChild (ViewGroup.java:4236)
  at android.widget.ListView.drawChild (ListView.java:3590)
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4022)
  at android.widget.AbsListView.dispatchDraw (AbsListView.java:2638)
  at android.widget.ListView.dispatchDraw (ListView.java:3585)
  at android.view.View.draw (View.java:19195)
  at android.widget.AbsListView.draw (AbsListView.java:4310)
  at android.view.View.draw (View.java:19062)
  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.buildDrawingCacheImpl (View.java:18440)
  at android.view.View.buildDrawingCache (View.java:18300)
  at android.view.View.draw (View.java:18912)
  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.ViewRootImpl.drawSoftware (ViewRootImpl.java:3105)
  at android.view.ViewRootImpl.draw (ViewRootImpl.java:3019)
  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)
  at android.view.Choreographer.doFrame (Choreographer.java:658)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)
  at android.os.Handler.handleCallback (Handler.java:790)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6494)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:440)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)

1 个答案:

答案 0 :(得分:0)

我找到了此异常的原因。然后,我为该异常提出了解决方案。

原因:加载图标时,可以返回在OREO和更高版本中可绘制的位图。因此,如果您使用;

   imageView.setBackground(info.loadIcon(getPackageManager());

当info.loadIcon()方法返回bitmapDrawable时,您将获得java.lang.IllegalArgumentException。您可以使用以下方法来解决此问题。

   X = info.loadIcon(getPackageManager();
   if (X instanceOf Bitmap)
       imageView_appIcon.setImageBitmap(X);
   else
       imageView_appIcon.setBackground(X);

希望,它会有所帮助。