gpt4 book ai didi

android - LayerDrawable 异常

转载 作者:太空狗 更新时间:2023-10-29 14:43:42 28 4
gpt4 key购买 nike

我有一个使用 android 支持库版本 23.2.1 的 android 应用程序,一切正常。但是,我昨天将 android 支持库版本更新为 25.2.0 并意识到一些用户遇到了这个异常(通过 Fabric crashlytics),但我无法重现它。

这是崩溃日志:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:959)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1007)
at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:133)
at android.graphics.drawable.LayerDrawable.<init>(LayerDrawable.java:126)
at android.graphics.drawable.LayerDrawable$LayerState.newDrawable(LayerDrawable.java:1048)
at android.content.res.Resources.getCachedDrawableLocked(Resources.java:2777)
at android.content.res.Resources.getCachedDrawable(Resources.java:2745)
at android.content.res.Resources.loadDrawable(Resources.java:2586)
at android.content.res.Resources.getDrawable(Resources.java:900)
at android.content.Context.getDrawable(Context.java:408)
at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:30)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:372)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:425)
at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:129)
at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:211)
at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:186)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:197)
at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:479)
at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1160)
at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:95)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:234)
at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:292)
at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1047)
at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1074)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:460)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

这似乎与菜单 View 有关。菜单选项的布局是:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".tablet.ui.navimenu.ContainerActivity">

<item
android:id="@+id/memo_fragment"
android:icon="@drawable/ic_class_white_24dp"
android:orderInCategory="100"
android:title="@string/memo_fragment"
app:showAsAction="always" />

<item
android:id="@+id/notification_fragment"
android:icon="@drawable/layerlist_menu_notification"
android:orderInCategory="200"
android:title="@string/notification_fragment"
app:showAsAction="always" />

</menu>

layerlist_menu_notification 布局是一个带有徽章的图标:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/ic_notification"
android:drawable="@drawable/ic_notifications_white_24dp"
android:gravity="center" />

<!-- set a place holder Drawable so android:drawable isn't null -->
<item
android:id="@+id/ic_badge"
android:drawable="@drawable/ic_notifications_white_24dp" />
</layer-list>

知道哪里出了问题吗?

最佳答案

尝试在 build.gradle 中更改以下内容

 compileSdkVersion 25
buildToolsVersion "25.0.2"
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'

关于android - LayerDrawable 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43447257/

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