susonthapa/curved-bottom-navigation

crash sometime happened

Opened this issue · 31 comments

.UnsupportedOperationException: Sorting went bad, the start event should always be at index 0

Can you give more information about the issue like when it happens, or maybe post the stack trace.

Hello
2021-07-16 10:33:53.922 23564-23564/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: story.reels.video.downloader, PID: 23564
java.lang.UnsupportedOperationException: Sorting went bad, the start event should always be at index 0
at android.animation.AnimatorSet.sortAnimationEvents(AnimatorSet.java:1638)
at android.animation.AnimatorSet.createDependencyGraph(AnimatorSet.java:1534)
at android.animation.AnimatorSet.initAnimation(AnimatorSet.java:700)
at android.animation.AnimatorSet.start(AnimatorSet.java:719)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
at np.com.susanthapa.curved_bottom_navigation.BottomNavItemView.startIntermediateAnimation(BottomNavItemView.kt:58)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.getBezierCurveAnimation$lambda-11$lambda-10(CurvedBottomNavigationView.kt:609)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.lambda$HfusvZnYG6MdA8klc2s64vbnySs(Unknown Source:0)
at np.com.susanthapa.curved_bottom_navigation.-$$Lambda$CurvedBottomNavigationView$HfusvZnYG6MdA8klc2s64vbnySs.onAnimationUpdate(Unknown Source:19)
at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1558)
at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:684)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:647)
at android.animation.ValueAnimator.start(ValueAnimator.java:1079)
at android.animation.ValueAnimator.start(ValueAnimator.java:1098)
at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1091)
at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1149)
at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1234)
at android.animation.AnimatorSet.start(AnimatorSet.java:729)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.animateItemSelection(CurvedBottomNavigationView.kt:534)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.onMenuItemClick(CurvedBottomNavigationView.kt:490)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController$lambda-6(CurvedBottomNavigationView.kt:387)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.lambda$llKMWHA5k7PUlYtvwsA96TEIQxI(Unknown Source:0)
at np.com.susanthapa.curved_bottom_navigation.-$$Lambda$CurvedBottomNavigationView$llKMWHA5k7PUlYtvwsA96TEIQxI.onDestinationChanged(Unknown Source:2)
at androidx.navigation.NavController.addOnDestinationChangedListener(NavController.java:233)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController(CurvedBottomNavigationView.kt:378)
at instagram.photo.video.downloader.repost.insta.home.HomeActivity.setupListeners(HomeActivity.kt:72)
at instagram.photo.video.downloader.repost.insta.home.HomeActivity.onStart(HomeActivity.kt:26)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
at android.app.Activity.performStart(Activity.java:7924)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3332)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7560)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

more likely not setting the setupWithNavController makes things work, but if pass a navController it breaks. My only doubt was since internally both onMenuItemClick i don't know whats the issue

Can you reproduce the issue, if so please mention the steps to reproduce.

I can't promise you the steps that might reproduce the same error. I have two projects that use the same component. One is just a test app with your package to test, while as other is a production app. Both use the same code and same versions of navigation fragment. But the test works fine but not the production app since even tho all the code is the same. We can get on a meet where I can show you the issue if you want to.

Ok, let's talk on skype. Can you give me your skype id?

Or you can attach some videos of it.

Sorry, can I get back to you on monday

Its fine, you can upload a video and I will take a look

Hello,
Sorry for replying late. I am not sure how useful are the videos. the prod application just crashes when you open the app with this bug.

  java.lang.RuntimeException: initialize menu by calling setMenuItems() before setting up with NavController
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController(CurvedBottomNavigationView.kt:370)
        at instagram.photo.video.downloader.repost.insta.home.HomeActivity.setupListeners(HomeActivity.kt:118)
        at instagram.photo.video.downloader.repost.insta.home.HomeActivity.onStart(HomeActivity.kt:63)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1436)
        at android.app.Activity.performStart(Activity.java:8158)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3566)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8061)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

My fix for this was to write my own menuItemClickListener and remove the navListener, where I think the problem lies.

        binding.cbnvHome.setMenuItems(menuItems, 2)
        binding.cbnvHome.setOnMenuItemClickListener { cbnMenuItem, index ->
            if (cbnMenuItem.destinationId == -1) {
                throw RuntimeException("please set a valid id, unable the navigation!")
            }
            val builder = NavOptions.Builder()
                .setLaunchSingleTop(true)
                .setEnterAnim(R.anim.nav_default_enter_anim)
                .setExitAnim(R.anim.nav_default_exit_anim)
                .setPopEnterAnim(R.anim.nav_default_pop_enter_anim)
                .setPopExitAnim(R.anim.nav_default_pop_exit_anim)
            // pop to the navigation graph's start  destination
            builder.setPopUpTo(findStartDestination(navController.graph).id, false)
            val options = builder.build()
            try {
                navController.navigate(cbnMenuItem.destinationId, null, options)
            } catch (e: IllegalArgumentException) {
                Log.w("HOME", "unable to navigate!", e)
            }
        }

obviously, any directions from the NavController wouldn't work so there is no point trying.

But a blank Project with just this much works fine.

package com.jeevan.bottomnavigation

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.findNavController
import np.com.susanthapa.curved_bottom_navigation.CbnMenuItem
import np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onStart() {
        super.onStart()
        val cbnv : CurvedBottomNavigationView = findViewById(R.id.nav_view)

        val menuItems = arrayOf(
            CbnMenuItem(
                R.drawable.ic_download, // the icon
                R.drawable.anim, // the AVD that will be shown in FAB
                R.id.downloadFragment // optional if you use Jetpack Navigation
            ),
            CbnMenuItem(
                R.drawable.ic_instagram,
                R.drawable.anim,
                R.id.instagramFragment
            ),
            CbnMenuItem(
                R.drawable.ic_post_saver,
                R.drawable.anim,
                R.id.postSaverFragment
            ),
            CbnMenuItem(
                R.drawable.ic_tools,
                R.drawable.anim,
                R.id.toolFragment
            ),
        )
        cbnv.setMenuItems(menuItems)
        cbnv.setupWithNavController(findNavController(R.id.nav_host_fragment))
    }
}

Also setting the default navController layout to something else other than 0 index leads to something like this
WhatsApp Image 2021-07-30 at 11 13 04 AM

The stack trace suggests that you are setting navController before setting the menuItems. I will verify the second case.

sorry that was the wrong stack trace, here is the correct one

java.lang.UnsupportedOperationException: Sorting went bad, the start event should always be at index 0
        at android.animation.AnimatorSet.sortAnimationEvents(AnimatorSet.java:1638)
        at android.animation.AnimatorSet.createDependencyGraph(AnimatorSet.java:1534)
        at android.animation.AnimatorSet.initAnimation(AnimatorSet.java:700)
        at android.animation.AnimatorSet.start(AnimatorSet.java:719)
        at android.animation.AnimatorSet.start(AnimatorSet.java:684)
        at np.com.susanthapa.curved_bottom_navigation.BottomNavItemView.startIntermediateAnimation(BottomNavItemView.kt:58)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.getBezierCurveAnimation$lambda-11$lambda-10(CurvedBottomNavigationView.kt:609)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.lambda$HfusvZnYG6MdA8klc2s64vbnySs(Unknown Source:0)
        at np.com.susanthapa.curved_bottom_navigation.-$$Lambda$CurvedBottomNavigationView$HfusvZnYG6MdA8klc2s64vbnySs.onAnimationUpdate(Unknown Source:19)
        at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1566)
        at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:692)
        at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:655)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1087)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1106)
        at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1099)
        at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1149)
        at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1234)
        at android.animation.AnimatorSet.start(AnimatorSet.java:729)
        at android.animation.AnimatorSet.start(AnimatorSet.java:684)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.animateItemSelection(CurvedBottomNavigationView.kt:534)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.onMenuItemClick(CurvedBottomNavigationView.kt:490)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController$lambda-6(CurvedBottomNavigationView.kt:387)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.lambda$llKMWHA5k7PUlYtvwsA96TEIQxI(Unknown Source:0)
        at np.com.susanthapa.curved_bottom_navigation.-$$Lambda$CurvedBottomNavigationView$llKMWHA5k7PUlYtvwsA96TEIQxI.onDestinationChanged(Unknown Source:2)
        at androidx.navigation.NavController.addOnDestinationChangedListener(NavController.java:233)
        at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController(CurvedBottomNavigationView.kt:378)
        at instagram.photo.video.downloader.repost.insta.home.HomeActivity.setupListeners(HomeActivity.kt:97)
        at instagram.photo.video.downloader.repost.insta.home.HomeActivity.onStart(HomeActivity.kt:63)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1436)
        at android.app.Activity.performStart(Activity.java:8158)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3566)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8061)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

Upon further inspection, I have realised that setting the active index while initializing the menuItems like this solves my issue.

 binding.cbnvHome.setMenuItems(menuItems,2)

This works because setup navController calls onMenuItemClick and onMenuItemClickhas a check that says.

if (selectedIndex == index) {
       Log.i(TAG, "same icon multiple clicked, skipping animation!")
       return
}

since the selectedIndex is equal to index it works.

but otherwise this function is executed animateItemSelection

and inside this function there is some code with AnimatorSet

        animatorSet = AnimatorSet()
        animatorSet.playTogether(centerYAnimatorHide, offsetAnimator, centerYAnimatorShow)
        animatorSet.interpolator = FastOutSlowInInterpolator()
        animatorSet.start()

start throws mee the error.

hope this is helpful

Thanks for the information. I will fix this issue when I have some free time.Until then you can use your work around.

i am getting the issue of Caused by: android.content.res.Resources$NotFoundException: why my resource png file is not showing

i am getting the issue of Caused by: android.content.res.Resources$NotFoundException: why my resource png file is not showing

This library is built to work with AnimatedVectorDrawable, if you are passing anything other than AVD, then it won't work.

Upon further inspection, I have realised that setting the active index while initializing the menuItems like this solves my issue.

 binding.cbnvHome.setMenuItems(menuItems,2)

This works because setup navController calls onMenuItemClick and onMenuItemClickhas a check that says.

if (selectedIndex == index) {
       Log.i(TAG, "same icon multiple clicked, skipping animation!")
       return
}

since the selectedIndex is equal to index it works.

but otherwise this function is executed animateItemSelection

and inside this function there is some code with AnimatorSet

        animatorSet = AnimatorSet()
        animatorSet.playTogether(centerYAnimatorHide, offsetAnimator, centerYAnimatorShow)
        animatorSet.interpolator = FastOutSlowInInterpolator()
        animatorSet.start()

start throws mee the error.

So after inspection I think I found the problem. The problem is that the home destination that have been setup in navigation graph should match the active index in setupMenuItems() function . I have reproduced the issues and I think this is the cause. I will update the README, let me know if this is the issue that you have been facing.

i am getting the issue of Caused by: android.content.res.Resources$NotFoundException: why my resource png file is not showing

This library is built to work with AnimatedVectorDrawable, if you are passing anything other than AVD, then it won't work.

ok thanks it works now but i want to be the selected icon fully inside the bottom bar but here it is half outside is there any way

i am getting the issue of Caused by: android.content.res.Resources$NotFoundException: why my resource png file is not showing

This library is built to work with AnimatedVectorDrawable, if you are passing anything other than AVD, then it won't work.

ok thanks it works now but i want to be the selected icon fully inside the bottom bar but here it is half outside is there any way

Can you attach some screenshots and also the code that you have used to setup the bottom navigation.

i am getting the issue of Caused by: android.content.res.Resources$NotFoundException: why my resource png file is not showing

This library is built to work with AnimatedVectorDrawable, if you are passing anything other than AVD, then it won't work.

ok thanks it works now but i want to be the selected icon fully inside the bottom bar but here it is half outside is there any way

Can you attach some screenshots and also the code that you have used to setup the bottom navigation.

there is no problem with the design it is as in the image shown here but i want the icon completely inside the bottom bar but in your design half of the selected item is outside and half is inside the bottom bar i want the selected item to be completely inside the bottom bar

Sorry this is currently not supported.

Is there any solution for this @susonthapa ?

Can you post some screen shot of the design that you are trying to replicate?

The stack trace suggests that you are setting navController before setting the menuItems. I will verify the second case.

Thanks for the information. I will fix this issue when I have some free time.Until then you can use your work around.

Hi Susonthapa,
Is this issue fixed? Application is crashing with this stack trace.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.<>/com.<>.MainActivity}: java.lang.UnsupportedOperationException: Sorting went bad, the start event should always be at index 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3735)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3903)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5828)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5734)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2328)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:255)
at android.app.ActivityThread.main(ActivityThread.java:8212)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by: java.lang.UnsupportedOperationException: Sorting went bad, the start event should always be at index 0
at android.animation.AnimatorSet.sortAnimationEvents(AnimatorSet.java:1638)
at android.animation.AnimatorSet.createDependencyGraph(AnimatorSet.java:1534)
at android.animation.AnimatorSet.initAnimation(AnimatorSet.java:700)
at android.animation.AnimatorSet.start(AnimatorSet.java:719)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
at np.com.susanthapa.curved_bottom_navigation.BottomNavItemView.startIntermediateAnimation(BottomNavItemView.kt:58)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.getBezierCurveAnimation$lambda-11$lambda-10(CurvedBottomNavigationView.kt:609)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.$r8$lambda$HfusvZnYG6MdA8klc2s64vbnySs(Unknown Source:0)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView$$ExternalSyntheticLambda0.onAnimationUpdate(Unknown Source:19)
at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1579)
at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:692)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:655)
at android.animation.ValueAnimator.start(ValueAnimator.java:1087)
at android.animation.ValueAnimator.start(ValueAnimator.java:1106)
at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1099)
at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1149)
at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1234)
at android.animation.AnimatorSet.start(AnimatorSet.java:729)
at android.animation.AnimatorSet.start(AnimatorSet.java:684)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.animateItemSelection(CurvedBottomNavigationView.kt:534)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.onMenuItemClick(CurvedBottomNavigationView.kt:490)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController$lambda-6(CurvedBottomNavigationView.kt:387)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.$r8$lambda$llKMWHA5k7PUlYtvwsA96TEIQxI(Unknown Source:0)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView$$ExternalSyntheticLambda4.onDestinationChanged(Unknown Source:2)
at androidx.navigation.NavController.addOnDestinationChangedListener(NavController.kt:403)
at np.com.susanthapa.curved_bottom_navigation.CurvedBottomNavigationView.setupWithNavController(CurvedBottomNavigationView.kt:378)
E/AndroidRuntime: at com.<>MainActivity.onCreate(MainActivity.kt:35)
at android.app.Activity.performCreate(Activity.java:8151)
at android.app.Activity.performCreate(Activity.java:8135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3704)
... 13 more

I haven't been able to look into this, does the workaround fixes your issue?

Came here looking for a solution because we saw the same stack trace in crash reporting. We are unable to reproduce the issue locally to figure what exactly is going wrong.

Here is an issue tracker that may receive some guidance at some point https://issuetracker.google.com/issues/234749373

@susonthapa
Any update on this issue?
I am facing this one again & again

I had the same issue.
If the index of bottomNav and startDestination of navigation_graph do not match the UI glitches

I solved it like this

Firstly I am using it with navContoller and toolbar, so whatever your startDestination, that will be your index in the bottomNav

For Example:
I have 3 Fragments: homeFragment, notificationFragment and settingFragment. Now if in my navigation_graph I keep my startDestination: homeFragment and in my MainActivity I code like this bottomNav.setMenuItems(menuItems, 0)

startDestination: notificationFragment and bottomNav.setMenuItems(menuItems, 1)

@anitanTIC
Please read the README.

Note: Make sure the home destination in your navigation graph corresponds to the activeIndex that you have passed to setMenuItems().

This is most likely caused by the mismatch of IDs between the navigation graph and the index passed to setMenuItems.

I haven't looked into this library in a while and with Jetpack Compose becoming the standard I don't know how useful this library is.