skydoves / PowerMenu

:fire: Powerful and modernized popup menu with fully customizable animations.
Apache License 2.0
1.19k stars 174 forks source link

Crash application when dark mode #65

Closed realkalash closed 4 years ago

realkalash commented 4 years ago

Description Bug:

Everything works in light UI mode (Theme.MaterialComponents.DayNight.NoActionBar.Bridge) But when i try to open menu in Dark UI mode application is crashed

my code ->

val menu = createPowerMenu(requireContext()) {
            addItem(PowerMenuItem(getString(R.string.paid_driver_for_km), R.drawable.ic_delivery))
            addItem(PowerMenuItem(getString(R.string.paid_for_enter), R.drawable.ic_gate_black))
            addItem(PowerMenuItem(getString(R.string.paid_for_fuel), R.drawable.ic_fuel))
            addItem(PowerMenuItem(getString(R.string.paid_for_help), R.drawable.ic_person_black_24dp))
            addItem(PowerMenuItem(getString(R.string.paid_for_overload), R.drawable.ic_blur_circular_black_24dp))
            setLifecycleOwner(viewLifecycleOwner)
            setAnimation(MenuAnimation.SHOW_UP_CENTER)
            setMenuRadius(10F)
            setAutoDismiss(true)
            setWidth(1000)
            setTextSize(16)
            setTextColorResource(R.color.text_color_daynight)
            setMenuColorResource(R.color.cardview_daynight_background)
            setBackgroundColorResource(R.color.cardview_daynight_background)

            setOnMenuItemClickListener { position, item ->
                when (item.title) {
                    getString(R.string.paid_driver_for_km) -> end_day_fin_paid_forwarder_for_km?.visibility = View.VISIBLE
                    getString(R.string.paid_for_enter) -> end_day_fin_paid_for_enter?.visibility = View.VISIBLE
                    getString(R.string.paid_for_fuel) -> end_day_fin_paid_fuel?.visibility = View.VISIBLE
                    getString(R.string.paid_for_help) -> end_day_fin_paid_for_help?.visibility = View.VISIBLE
                    getString(R.string.paid_for_overload) -> end_day_fin_paid_for_overload?.visibility = View.VISIBLE
                }
            }
        }
        if (end_day_fin_add_outgo != null)
            menu.showAsDropDown(end_day_fin_add_outgo)

In Crashlytics error ->

Fatal Exception: android.content.res.Resources$NotFoundException
Resource ID #0x7f0800ab

com.skydoves.powermenu.MenuListAdapter.getView (MenuListAdapter.java:103)

in Logcat ->

android.content.res.Resources$NotFoundException: Resource ID #0x7f0800ab
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:228)
        at android.content.res.Resources.getValue(Resources.java:1346)
        at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:176)
        at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:141)
        at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:132)
        at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
        at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:90)
        at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:98)
        at com.skydoves.powermenu.MenuListAdapter.getView(MenuListAdapter.java:86)
        at android.widget.AbsListView.obtainView(AbsListView.java:3219)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1451)
        at android.widget.ListView.onMeasure(ListView.java:1358)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at androidx.cardview.widget.CardView.onMeasure(CardView.java:260)
        at com.google.android.material.card.MaterialCardView.onMeasure(MaterialCardView.java:160)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7139)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:24966)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3301)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2028)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2330)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1888)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8511)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
        at android.view.Choreographer.doFrame(Choreographer.java:696)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

I tried to use without and with background colors. An error still exists

skydoves commented 4 years ago

The error message shows one of the image resources is not exist to set an icon.

addItem(PowerMenuItem(getString(R.string.paid_driver_for_km), R.drawable.ic_delivery))
addItem(PowerMenuItem(getString(R.string.paid_for_enter), R.drawable.ic_gate_black))
addItem(PowerMenuItem(getString(R.string.paid_for_fuel), R.drawable.ic_fuel))
addItem(PowerMenuItem(getString(R.string.paid_for_help), R.drawable.ic_person_black_24dp))
addItem(PowerMenuItem(getString(R.string.paid_for_overload), R.drawable.ic_blur_circular_black_24dp))
realkalash commented 4 years ago

Thanks. The problem really was in the image resources. I had to copy pictures from the drawable-notnight folder to drawable and it's work