Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InflateException: Error inflating class ImageView for VectorDrawableCompat

VectorDrawableCompat finally made its way into support library in SDK 23. But it doesn't seem to work, or maybe I'm missing something.

drawable/mypic.xml:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<group
    android:name="rotationGroup"
    android:pivotX="300.0"
    android:pivotY="300.0"
    android:rotation="45.0" >
    <path
        android:name="v"
        android:fillColor="#000000"
        android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
</group>
</vector>

fragment_bla.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/mypic"
    android:scaleType="centerCrop" />

</FrameLayout>

This code works in Lollipop, but not in KitKat. What am I missing?


Exception:

09-06 14:26:53.637  31820-31820/com.bla E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.bla, PID: 31560
android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageView
        at android.view.LayoutInflater.createView(LayoutInflater.java:623)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
        at com.hohero.fragment.Intro1Fragment.onCreateView(Intro1Fragment.java:14)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
like image 925
wiradikusuma Avatar asked Sep 06 '15 06:09

wiradikusuma


1 Answers

I believe the problem is android:src="@drawable/mypic" in your imageView setup.

Change that to app:srcCompat="@drawable/mypic"

Then you should be good to go.

More details, please refer to: https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.mvuq06x1k

like image 186
Tenghui Zhu Avatar answered Nov 04 '22 21:11

Tenghui Zhu