Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

android - VectorDrawableCompat Resources$NotFoundException on KitKat and below

When I enable

vectorDrawables.useSupportLibrary = true

I get a lot of resourceNotFoundExceptions on KitKat and below devices. I get this for NavigationView for Menus and also for ImageViews with app:srcCompat

android.content.res.Resources$NotFoundException: Resource ID #0x7f02006b
at android.content.res.Resources.getValue(Resources.java:2305)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:268)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:114)
at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:206)
at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:182)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
at  android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:480)
at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1053)
at android.support.v7.app.AppCompatDelegateImplV7.preparePanel(AppCompatDelegateImplV7.java:1345)
at android.support.v7.app.AppCompatDelegateImplV7.doInvalidatePanelMenu(AppCompatDelegateImplV7.java:1583)
at android.support.v7.app.AppCompatDelegateImplV7.access$100(AppCompatDelegateImplV7.java:89)
at android.support.v7.app.AppCompatDelegateImplV7$1.run(AppCompatDelegateImplV7.java:128)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:110)

for NavigationView

Process: org.ligi.gobandroid_hd, PID: 11473
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.ligi.gobandroid_hd/org.ligi.gobandroid_hd.ui.game_setup.GoSetupActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.NavigationView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
    at android.app.ActivityThread.access$900(ActivityThread.java:172)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5653)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.NavigationView
    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
    at org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity.setContentView(GobandroidFragmentActivity.java:85)
    at org.ligi.gobandroid_hd.ui.GoActivity.onCreate(GoActivity.java:108)
    at android.app.Activity.performCreate(Activity.java:5541)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)?
    at android.app.ActivityThread.access$900(ActivityThread.java:172)?
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)?
    at android.os.Handler.dispatchMessage(Handler.java:102)?
    at android.os.Looper.loop(Looper.java:146)?
    at android.app.ActivityThread.main(ActivityThread.java:5653)?
    at java.lang.reflect.Method.invokeNative(Native Method)?
    at java.lang.reflect.Method.invoke(Method.java:515)?
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)?
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)?
    at dalvik.system.NativeStart.main(Native Method)?
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:600)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)?
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)?
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)?
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)?
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)?
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)?
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)?
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)?
    at org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity.setContentView(GobandroidFragmentActivity.java:85)?
    at org.ligi.gobandroid_hd.ui.GoActivity.onCreate(GoActivity.java:108)?
    at android.app.Activity.performCreate(Activity.java:5541)?
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)?
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)?
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)?
    at android.app.ActivityThread.access$900(ActivityThread.java:172)?
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)?
    at android.os.Handler.dispatchMessage(Handler.java:102)?
    at android.os.Looper.loop(Looper.java:146)?
    at android.app.ActivityThread.main(ActivityThread.java:5653)?
    at java.lang.reflect.Method.invokeNative(Native Method)?
    at java.lang.reflect.Method.invoke(Method.java:515)?
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)?
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)?
    at dalvik.system.NativeStart.main(Native Method)?
 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020067
    at android.content.res.Resources.getValue(Resources.java:2305)
    at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:268)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
    at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
    at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:475)
    at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436)
    at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112)
    at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:241)
    at android.support.design.widget.NavigationView.<init>(NavigationView.java:169)
    at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
    at java.lang.reflect.Constructor.constructNative(Native Method)?
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)?
    at android.view.LayoutInflater.createView(LayoutInflater.java:600)?
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)?
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)?
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)?
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)?
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)?
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)?
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)?
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)?
    at org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity.setContentView(GobandroidFragmentActivity.java:85)?
    at org.ligi.gobandroid_hd.ui.GoActivity.onCreate(GoActivity.java:108)?
    at android.app.Activity.performCreate(Activity.java:5541)?
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)?
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)?
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)?
    at android.app.ActivityThread.access$900(ActivityThread.java:172)?
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)?
    at android.os.Handler.dispatchMessage(Handler.java:102)?
    at android.os.Looper.loop(Looper.java:146)?
    at android.app.ActivityThread.main(ActivityThread.java:5653)?
    at java.lang.reflect.Method.invokeNative(Native Method)?
    at java.lang.reflect.Method.invoke(Method.java:515)?
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)?
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)?
    at dalvik.system.NativeStart.main(Native Method)?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To support versions before Lollipop, use

com.android.support:appcompat-v7:24.0.0 (or later)

support library.

And then, instead of

ContextCompat.getDrawable(view.getContext(), id);

use this one

AppCompatResources.getDrawable(view.getContext(), id);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...