膨胀 class ImageView Resources$NotFoundException 无效的可绘制标签向量时出错
Error inflating class ImageView Resources$NotFoundException invalid drawable tag vector
我在某些设备上遇到异常 -
Fatal Exception: android.view.InflateException: Binary XML file line #6: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at
Caused by android.content.res.Resources$NotFoundException: File res/drawable/ic_folder_red_24dp.xml from drawable resource ID #0x7f0800a2
at android.content.res.Resources.loadDrawable(Resources.java:3066)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:133)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatDelegateImpl.addContentView(AppCompatDelegateImpl.java)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
at android.content.res.Resources.loadDrawable(Resources.java:3062)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:133)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatDelegateImpl.addContentView(AppCompatDelegateImpl.java)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
我的drawable放在src->main->res->drawable文件夹中,layout放在src->main->res->layout文件夹中。
下面是可绘制和布局文件-
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp">
<ImageView
android:id="@+id/folderImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_folder_red_24dp" />
可绘制
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorPrimary"
android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
</vector>
改变
android:src="@drawable/ic_folder_red_24dp"
至
app:srcCompat="@drawable/ic_folder_red_24dp"
解决了我的问题
我在某些设备上遇到异常 -
Fatal Exception: android.view.InflateException: Binary XML file line #6: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at
Caused by android.content.res.Resources$NotFoundException: File res/drawable/ic_folder_red_24dp.xml from drawable resource ID #0x7f0800a2
at android.content.res.Resources.loadDrawable(Resources.java:3066)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:133)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatDelegateImpl.addContentView(AppCompatDelegateImpl.java)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
at android.content.res.Resources.loadDrawable(Resources.java:3062)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:133)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java)
at androidx.appcompat.app.AppCompatDelegateImpl.addContentView(AppCompatDelegateImpl.java)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
我的drawable放在src->main->res->drawable文件夹中,layout放在src->main->res->layout文件夹中。 下面是可绘制和布局文件-
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp">
<ImageView
android:id="@+id/folderImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_folder_red_24dp" />
可绘制
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorPrimary"
android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
</vector>
改变
android:src="@drawable/ic_folder_red_24dp"
至
app:srcCompat="@drawable/ic_folder_red_24dp"
解决了我的问题