Search code examples
androidandroid-resourcesruntimeexceptionandroid-vectordrawable

Empty Vector Drawable causes a ResourceNotFound Exception in runtime


I cannot use an empty vector drawable as place holder:

<?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 does not point out any rendering problem in the Activity preview but in runtime I get this fatal exception:

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

Solution

  • Updated

    There is no path in your vector, adding a path that doesn't draw anything should fix the error

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="dp"
        android:height="1dp"
        android:viewportWidth="1"
        android:viewportHeight="1">
    
      <path
          android:pathData="M0,0Z"
          android:fillColor="#ffffff"/>
    
    </vector>