IllegalStateException: Link does not have a NavController set

前端 未结 9 2247
故里飘歌
故里飘歌 2020-11-29 03:58

I\'m using Android Navigation Component for Navigation. I have a LoginFragment which has a button to transition to SignUpFragment. On clicking the button I\'m getting this e

9条回答
  •  眼角桃花
    2020-11-29 04:15

    A weird thing happens to me, below code snippet was working on normal flow from Fragment1 to fragment2, but after coming to fragment1 and on again navigate fragment2, this was throwing the "Navigation controller not set for the view" error.

        binding.ivIcon.setOnClickListener(v -> {
                Openfragment2(v);});
    
    private void Openfragment2(View view) {
        Navigation.findNavController(binding.ivIcon).navigate(R.id.fragment2);
    
    }
    

    Here problem was in view, in findNavController need to pass the onclicked view.

    private void Openfragment2(View view) {
        Navigation.findNavController(view).navigate(R.id.fragment2);
    
    }
    

提交回复
热议问题