Empty Vector Drawable在运行时导致ResourceNotFound异常

时间:2018-06-07 12:28:26

标签: android android-resources runtimeexception android-vectordrawable

我不能使用空的矢量drawable作为占位符:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:viewportWidth="164.891"
    android:viewportHeight="75.543"
    android:width="164.891dp"
    android:height="75.543dp"></vector>

Android Studio没有在活动预览中指出任何渲染问题,但在运行时我得到了这个致命的例外:

Caused by: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class ImageView
     Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class ImageView
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.xxxx.yyyy:drawable/product_logo_image with resource ID #0x7f080121
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/product_logo_image.xml from drawable resource ID #0x7f080121

2 个答案:

答案 0 :(得分:2)

你的矢量中没有路径,添加空路径应该修复错误

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:viewportWidth="164.891"
    android:viewportHeight="75.543"
    android:width="164.891dp"
    android:height="75.543dp">
<path/>
</vector>

答案 1 :(得分:0)

也许Manohar的答案中缺少的是一些数据,因此不会像xinaiz所评论的那样崩溃

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:viewportWidth="1dp"
    android:viewportHeight="1dp"
    android:width="1dp"
    android:height="1dp">
  <path
      android:fillColor="#00FFFFFF" 
      android:pathData=""/>
</vector>

您可以使用widthheight来满足您的需求,并且填充颜色并不重要,只要您将前两个零设为透明即可。