gpt4 book ai didi

android - 带有矢量可绘制对象的 ImageView 的 Resources$NotFoundException

转载 作者:行者123 更新时间:2023-12-01 13:43:21 25 4
gpt4 key购买 nike

我遇到了崩溃 - Resources$NotFoundException 在 Activity 创建时可绘制的矢量。在 21 岁之前崩溃。

  • Android Studio 2.1
  • 支持库 24.0.0
  • Gradle 插件 2.1.0
  • targetSDK 23
  • minSdk 15
  • 构建工具版本 23.0.2
  • 在模拟器 sdk 16 上调试

在我的应用程序模块 build.gradle 中:

vectorDrawables.useSupportLibrary = true

该 Activity 是 AppCompatActivity 的子类。该 fragment 是一个支持 fragment 的子类。

在我调用的 Activity 中:

static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

View 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.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

我看不出有什么问题。我遵循矢量的所有指南,但仍然

最佳答案

self 回答:将 xml 从 drawable-anydpi 移动到 drawable 解决了这个问题。 (但布局编辑器仍然不起作用)。

关于android - 带有矢量可绘制对象的 ImageView 的 Resources$NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com