title: Navigation with Fragment that takes a parameter
body: <p>My application consists of a <code>ViewPager</code> that contains <code>9 Fragments</code> of the same type. This Fragment takes a parameter in its constructor upon declaration as shown below.</p>
  <p><strong>NewsFragment.kt</strong></p>
  <pre class="lang-kotlin prettyprint-override"><code>class NewsFragment(section: NewsSection) : Fragment() {
     //...
  }
  </code></pre>
  <p><strong>CategoryFragmentPagerAdapter.kt</strong></p>
  <pre class="lang-kotlin prettyprint-override"><code>class CategoryFragmentPagerAdapter(fm: FragmentManager)
      : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
  
      override fun getItem(position: Int): Fragment =
          NewsFragment(NewsSection.getItem(position))
  
      override fun getCount(): Int = NewsSection.values().size
  
      override fun getPageTitle(position: Int): CharSequence =
           NewsSection.getItem(position).sectionName
  
  }
  </code></pre>
  <p>And this fragment contains some actions which should navigate the user to some other fragments.</p>
  <p>I tried to implement the navigation using the <code>Jetpack Navigation Component</code> method but looks it gives an error because the navigation graph can't accept a fragment with a parameter.</p>
  <p>Any ideas on how to implement the <code>Navigation</code> in such a situation?</p>
  <h2>Edit</h2>
  <hr />
  <p>So this is my <code>FragmentContainerView</code> in the activity's <code>XML layout</code></p>
  <pre><code>&lt;androidx.fragment.app.FragmentContainerView
                  android:id=&quot;@+id/fragment_container&quot;
                  android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  app:defaultNavHost=&quot;true&quot;
                  app:navGraph=&quot;@navigation/navigation&quot; /&gt;
  </code></pre>
  <p>and this is how I implement the <code>navController</code> in the activity</p>
  <pre class="lang-kotlin prettyprint-override"><code>override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          
          setupDataBinding()
          val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
          val navController = navHostFragment.navController
  }
  </code></pre>
  <p>I didn't add any more configuration, and this is the <code>error</code> that pops up when I run the app</p>
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.domain.news/com.domain.news.ui.activities.MainActivity}: android.view.InflateException: Binary XML file line #18 in com.domain.news:layout/activity_main: Binary XML file line #22 in com.domain.news:layout/content_main: Error inflating class androidx.fragment.app.FragmentContainerView
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3307)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3446)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
          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:2043)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:224)
          at android.app.ActivityThread.main(ActivityThread.java:7548)
          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)
       Caused by: android.view.InflateException: Binary XML file line #18 in com.domain.news:layout/activity_main: Binary XML file line #22 in com.domain.news:layout/content_main: Error inflating class androidx.fragment.app.FragmentContainerView
       Caused by: android.view.InflateException: Binary XML file line #22 in com.domain.news:layout/content_main: Error inflating class androidx.fragment.app.FragmentContainerView
       Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.domain.news.ui.fragments.news.NewsFragment: could not find Fragment constructor
          at androidx.fragment.app.Fragment.instantiate(Fragment.java:563)
          at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
          at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:390)
          at androidx.navigation.fragment.FragmentNavigator.instantiateFragment(FragmentNavigator.java:132)
          at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:162)
          at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:58)
          at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:71)
          at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:28)
          at androidx.navigation.NavController.navigate(NavController.java:1049)
          at androidx.navigation.NavController.onGraphCreated(NavController.java:633)
          at androidx.navigation.NavController.setGraph(NavController.java:586)
          at androidx.navigation.NavController.setGraph(NavController.java:551)
          at androidx.navigation.NavController.setGraph(NavController.java:533)
          at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:238)
          at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
          at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
          at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
          at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
          at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
          at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
          at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
          at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
          at androidx.fragment.app.FragmentContainerView.&lt;init&gt;(FragmentContainerView.java:166)
          at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:51)
  2020-09-19 20:39:22.012 16179-16179/com.domain.news E/AndroidRuntime:     at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
          at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
          at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
          at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
          at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1267)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
          at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1267)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
          at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
          at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
          at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
          at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
          at com.domain.news.utils.delegates.ActivityBindingProperty.createActivityBinding(Databinding.kt:20)
          at com.domain.news.utils.delegates.ActivityBindingProperty.getValue(Databinding.kt:16)
          at com.domain.news.ui.activities.MainActivity.getBinding(Unknown Source:10)
          at com.domain.news.ui.activities.MainActivity.setupBinding(MainActivity.kt:42)
          at com.domain.news.ui.activities.MainActivity.onCreate(MainActivity.kt:34)
          at android.app.Activity.performCreate(Activity.java:7893)
          at android.app.Activity.performCreate(Activity.java:7880)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3282)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3446)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
          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:2043)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:224)
          at android.app.ActivityThread.main(ActivityThread.java:7548)
          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)
       Caused by: java.lang.NoSuchMethodException: com.domain.news.ui.fragments.news.NewsFragment.&lt;init&gt; []
          at java.lang.Class.getConstructor0(Class.java:2332)
          at java.lang.Class.getConstructor(Class.java:1728)
          at androidx.fragment.app.Fragment.instantiate(Fragment.java:548)
              ... 66 more
  </code></pre>
  <p>And I can see from the last 3 lines that the reason is because of the fragment constructor</p>