1

I have a single activity app with different screens represented by composables. I am using navigation component to handle screen navigation.

My navigation component has AnimatedNavHost as:

 val navController = rememberAnimatedNavController()
    AnimatedNavHost(
            navController = navController,
            startDestination = Constants.SPLASH
        ) {
            composable(Constants.SPLASH) {
                Splash(navController = navController)
            }

I get the following error on running the app:

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
        at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost$lambda-3(AnimatedNavHost.kt:323)
        at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:158)
        at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:85)

But the code works fine on using 'NavHost' instead of 'AnimatedNavHost'.

My Accompanist navigation dependency is:

 implementation "com.google.accompanist:accompanist-navigation-animation:0.16.1"

My Kotlin compiler extension version is:

kotlinCompilerExtensionVersion '1.0.2'

My Kotlin version is:

'1.5.21'

I have been looking for the solution since hours, not able to find it. Please help me solve this. Thanks a lot!

Sparsh Dutta
  • 2,450
  • 4
  • 27
  • 54
  • Does this answer your question? [Explanation of ClassCastException in Java](https://stackoverflow.com/questions/907360/explanation-of-classcastexception-in-java) – Khaby Lame Sep 09 '21 at 08:38
  • @ElPrimo I have chosen the best answer for this question. That answer answers my question. – Sparsh Dutta Sep 09 '21 at 09:33
  • The suggested duplicate is not relevant because the exception is in library code. I'm voting to leave open. – Ryan M Sep 09 '21 at 09:49

1 Answers1

2

Your accompanist version is outdated. Make sure you're using latest version, which is 0.20.0 right now.

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220