带有矢量可绘制对象的 ImageView 的 Resources$NotFoundException
Resources$NotFoundException for ImageView with vector drawable
我遇到了崩溃 - Resources$NotFoundException
在创建 activity 时可绘制的矢量。在 21 岁之前崩溃。
- Android Studio 2.1
- 支持库 24.0.0
- Gradle 插件 2.1.0
- targetSdk 23
- minSdk 15
- buildToolsVersion 23.0.2
- 在模拟器 sdk 16 上调试
在应用程序模块中 build.gradle 我有:
vectorDrawables.useSupportLibrary = true
activity 是 AppCompatActivity
的子类。
该片段是支持 Fragment
.
的子类
在activity我打电话:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
视图xml部分:
<ImageView
android:layout_width="64dp"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_map_white_24dp"
android:background="@color/vibrant5"
android:scaleType="center"/>
矢量图xml:
<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="#FFffffff"
android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.buildware.geoworld/com.buildware.geocoord.activities.DashBoardActivity}: android.view.InflateException: Binary XML file line #212: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access0(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #212: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.buildware.geocoord.fragments.DashBoardFragment.onCreateView(DashBoardFragment.java:82)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1264)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1366)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2409)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.buildware.geoworld.activities.BaseActivity.setContentView(BaseActivity.java:383)
at com.buildware.geoworld.activities.BaseActivity.onCreate(BaseActivity.java:198)
at com.buildware.geoworld.activities.BaseNavActivity.onCreate(BaseNavActivity.java:124)
at com.buildware.geocoord.activities.DashBoardActivity.onCreate(DashBoardActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access0(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0200ca
at android.content.res.Resources.getValue(Resources.java:1013)
at android.support.v7.widget.AppCompatDrawabl
我看不出有什么问题。我遵循矢量的所有指南,但仍然
As of Android Support Library 23.3.0, support vector drawables can
only be loaded via app:srcCompat or setImageResource()
这可能会解决 xml 文件中的 InflateException
。
自我回答:
将 xml 从 drawable-anydpi
移动到 drawable
解决了这个问题。 (但布局编辑器仍然不起作用)。
对我来说,当我将支持库从 24 改回 23 时,问题就解决了。
不知道为什么,但 24 似乎破坏了 KitKat 兼容性。
我遇到了崩溃 - Resources$NotFoundException
在创建 activity 时可绘制的矢量。在 21 岁之前崩溃。
- Android Studio 2.1
- 支持库 24.0.0
- Gradle 插件 2.1.0
- targetSdk 23
- minSdk 15
- buildToolsVersion 23.0.2
- 在模拟器 sdk 16 上调试
在应用程序模块中 build.gradle 我有:
vectorDrawables.useSupportLibrary = true
activity 是 AppCompatActivity
的子类。
该片段是支持 Fragment
.
在activity我打电话:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
视图xml部分:
<ImageView
android:layout_width="64dp"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_map_white_24dp"
android:background="@color/vibrant5"
android:scaleType="center"/>
矢量图xml:
<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="#FFffffff"
android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.buildware.geoworld/com.buildware.geocoord.activities.DashBoardActivity}: android.view.InflateException: Binary XML file line #212: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access0(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #212: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.buildware.geocoord.fragments.DashBoardFragment.onCreateView(DashBoardFragment.java:82)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1264)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1366)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2409)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.buildware.geoworld.activities.BaseActivity.setContentView(BaseActivity.java:383)
at com.buildware.geoworld.activities.BaseActivity.onCreate(BaseActivity.java:198)
at com.buildware.geoworld.activities.BaseNavActivity.onCreate(BaseNavActivity.java:124)
at com.buildware.geocoord.activities.DashBoardActivity.onCreate(DashBoardActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access0(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0200ca
at android.content.res.Resources.getValue(Resources.java:1013)
at android.support.v7.widget.AppCompatDrawabl
我看不出有什么问题。我遵循矢量的所有指南,但仍然
As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat or setImageResource()
这可能会解决 xml 文件中的 InflateException
。
自我回答:
将 xml 从 drawable-anydpi
移动到 drawable
解决了这个问题。 (但布局编辑器仍然不起作用)。
对我来说,当我将支持库从 24 改回 23 时,问题就解决了。 不知道为什么,但 24 似乎破坏了 KitKat 兼容性。