我已经崩溃 - Resources$NotFoundException
用于创建活动时可绘制的矢量。在21岁之前崩溃。
在app模块build.gradle中我有:
vectorDrawables.useSupportLibrary = true
活动是AppCompatActivity
的子类。
该片段是支持Fragment
的子类。
在我正在打电话的活动中:
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"/>
vector drawable 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.access$600(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.access$600(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
我看不出任何可能出错的地方。我遵循矢量的所有指南,但仍然
答案 0 :(得分:1)
以下内容来自this question:
从Android支持库23.3.0开始,支持向量drawables即可 只能通过app:srcCompat或setImageResource()
加载
这可能会解决xml文件中的InflateException
。
答案 1 :(得分:1)
自应答:
将xml从drawable-anydpi
移动到drawable
解决了问题。 (但布局编辑器仍然无效)。
答案 2 :(得分:0)
对我而言,当我将支持库从24更改为23时,它就解决了。 不知道为什么,但24似乎打破了KitKat的兼容性。