title: app crashes when inflating second navigation host
body: <p>app crashes when starting a new activity with a navigation host.
  so my app contains two activities with a navigation graph and a navigation host each, when trying to inflate the second navigation host my app crashes.
  i cant seem to find any help online regarding the use of multiple activities with a navigation host each</p>
  
  <p>log:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.vois, PID: 22503
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vois/com.example.vois.register.RegisterActivity}: android.view.InflateException: Binary XML file line #9 in com.example.vois:layout/activity_register: Binary XML file line #9 in com.example.vois:layout/activity_register: Error inflating class fragment
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3447)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
          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:2146)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:237)
          at android.app.ActivityThread.main(ActivityThread.java:7762)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
       Caused by: android.view.InflateException: Binary XML file line #9 in com.example.vois:layout/activity_register: Binary XML file line #9 in com.example.vois:layout/activity_register: Error inflating class fragment
       Caused by: android.view.InflateException: Binary XML file line #9 in com.example.vois:layout/activity_register: Error inflating class fragment
       Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.vois.register.WelcomeFragment: calling Fragment constructor caused an exception
          at androidx.fragment.app.Fragment.instantiate(Fragment.java:541)
          at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
          at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2851)
          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:859)
          at androidx.navigation.NavController.onGraphCreated(NavController.java:503)
          at androidx.navigation.NavController.setGraph(NavController.java:460)
          at androidx.navigation.NavController.setGraph(NavController.java:425)
          at androidx.navigation.NavController.setGraph(NavController.java:407)
          at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:236)
          at androidx.fragment.app.Fragment.performCreate(Fragment.java:2586)
          at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:838)
          at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1133)
          at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1393)
          at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3205)
          at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
          at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
          at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
          at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
  E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
          at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
          at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
          at com.example.vois.register.RegisterActivity.onCreate(RegisterActivity.kt:40)
          at android.app.Activity.performCreate(Activity.java:7981)
          at android.app.Activity.performCreate(Activity.java:7970)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
          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:2146)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:237)
          at android.app.ActivityThread.main(ActivityThread.java:7762)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
       Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Constructor.newInstance0(Native Method)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
          at androidx.fragment.app.Fragment.instantiate(Fragment.java:523)
              ... 47 more
       Caused by: kotlin.TypeCastException: null cannot be cast to non-null type com.example.vois.register.RegisterActivity
          at com.example.vois.register.WelcomeFragment.&lt;init&gt;(WelcomeFragment.kt:44)
              ... 50 more
  </code></pre>
  
  <p>activity main navigation graph:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;navigation xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/navigation"
      app:startDestination="@id/contactsFragment"&gt;
  .......
  &lt;/navigation&gt;
  </code></pre>
  
  <p>activity main navigation host:</p>
  
  <pre><code>&lt;fragment
              android:id="@+id/nav_host_fragment"
              android:name="androidx.navigation.fragment.NavHostFragment"
              android:layout_width="0dp"
              android:layout_height="0dp"
              app:defaultNavHost="true"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toBottomOf="@+id/toolbar"
              app:navGraph="@navigation/navigation" /&gt;
  </code></pre>
  
  <p>activity register navigation graph:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;navigation xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/navigation_register"
      app:startDestination="@id/welcomeFragment"&gt;
  
      &lt;fragment
          android:id="@+id/welcomeFragment"
          android:name="com.example.vois.register.WelcomeFragment"
          android:label="fragment_welcome"
          tools:layout="@layout/fragment_welcome" &gt;
          &lt;action
              android:id="@+id/action_welcomeFragment_to_profileImageFragment"
              app:destination="@id/profileImageFragment" /&gt;
      &lt;/fragment&gt;
      &lt;fragment
          android:id="@+id/profileImageFragment"
          android:name="com.example.vois.register.ProfileImageFragment"
          android:label="fragment_profile_image"
          tools:layout="@layout/fragment_profile_image" &gt;
          &lt;action
              android:id="@+id/action_profileImageFragment_to_privacySettingsFragment"
              app:destination="@id/privacySettingsFragment" /&gt;
      &lt;/fragment&gt;
      &lt;fragment
          android:id="@+id/privacySettingsFragment"
          android:name="com.example.vois.register.PrivacySettingsFragment"
          android:label="fragment_privacy_settings"
          tools:layout="@layout/fragment_privacy_settings" /&gt;
  &lt;/navigation&gt;
  </code></pre>
  
  <p>activity register host:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:fitsSystemWindows="true"&gt;
  
  
      &lt;fragment
          android:id="@+id/nav_host_fragment_register"
          android:name="androidx.navigation.fragment.NavHostFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:defaultNavHost="false"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:navGraph="@navigation/navigation_register" /&gt;
  
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p>how i start the second activity with the navigation host:</p>
  
  <pre><code>val intent = Intent(this, RegisterActivity::class.java)
              intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK.or(Intent.FLAG_ACTIVITY_NEW_TASK)
              startActivity(intent)
              this.finish()
  </code></pre>