5

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
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Seraphim's
  • 12,559
  • 20
  • 88
  • 129

2 Answers2

8

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>
Boy
  • 7,010
  • 4
  • 54
  • 68
Manohar
  • 22,116
  • 9
  • 108
  • 144
  • 2
    Bad idea. This caused crash on Android 5.1 using AndroidX: `java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.core.content.res.ComplexColorCompat.isStateful()' on a null object reference` – xinaiz May 08 '19 at 13:39
  • Ok thanks , I didn't knew , feel free to edit the answer with the fix you applied . – Manohar May 08 '19 at 16:18
-1

Perhaps what's missing in Manohar's answer is a bit of data so it doesn't crash as commented by 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>

You can play with width and height to fill your needs, and the fill color doesn't really matter as long as you set it as transparent with the first two zeroes

Chisko
  • 3,092
  • 6
  • 27
  • 45