0

Value passed as String should be received as String

Steps to reproduce:-

  1. Fragment needs to be added as startDestination in NavGraph
  2. Add a default argument in fragment of string type and default value that contains only digits

3a.If the value is small like "987987", it'll work good.

3b. If the value is around 15 characters ex:- "987987987987987" , it'll be received as "9.8798797E14"

3c. If the value is pretty large around 30 characters, it'll be received as "infinity"

Nav graph version used - 2.5.3

NavGraph

    <?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/home_nav"
    app:startDestination="@id/verifyProductFragment">
    <fragment
        android:id="@+id/verifyProductFragment"
        android:name="com.app.fragments.VerifyProductFragment"
        android:label="VerifyProductFragment" >
        <argument android:name="imeiNo"
            app:argType="string"
            android:defaultValue="987987987987987"/>
    </fragment>
</navigation>

Fragment

class VerifyProductFragment : Fragment() {

    private val args by navArgs<VerifyProductFragmentArgs>()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ) = ComposeView(requireContext()).apply {
        setContent {
            Log.e("data", args.imeiNo, )
        }
    }

}

Dependencies

def nav_version = "2.5.3"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
Kozmotronik
  • 2,080
  • 3
  • 10
  • 25
  • This information is not enough to see any possible errors, show your navgraph implementation. – Kozmotronik May 10 '23 at 07:04
  • Next time consider adding all relevant tags like `kotlin`. As far as I see you use composable, don't you? If you do you can add its tag as well. This might be caused because kotlin is type agnostic. Have you tried to get `imeiNo` as? String? Try logging the following statement and let me know what you see in the log: `(args.imeiNo is String)`. – Kozmotronik May 10 '23 at 07:50
  • @Kozmotronik Yes I tried `imeiNo as String` and studio gives a warning that it is redundant as the argument received is String only but somehow the value is changed. For `(args.imeiNo is String)` I get true in logs. – Vikalp Vashisth May 10 '23 at 12:20

0 Answers0