Jetpack compose navigation crash when adding arguments to route with repeated NavType?

102 views Asked by At

I am getting following crash error message

java.lang.IllegalArgumentException: Query parameter  must only be present once in android-app://androidx.navigation/page_detail?arg1={arg1}. To support repeated query parameters, use an array type for your argument and the pattern provided in your URI will be used to parse each query parameter instance.

And this is arguments

val arguments = listOf(
        navArgument(KEY_1){
            defaultValue = ""
            type = NavType.StringType
        },
        navArgument(KEY_2){
            defaultValue = ""
            type = NavType.StringType
        },
        navArgument(KEY_3){
            defaultValue = ""
            type = NavType.StringType
        },
        navArgument(KEY_5){
            defaultValue = -1
            type = NavType.LongType
        }
    )

This error happens only when I repeat the NavType more than twice eg NavType.StringType

1

There are 1 answers

0
Jeevan Rupacha On

The problem was sending empty string value for two or more arguments value so if arg value is empty make sure some default text like "-1".