title: Multiple exceptions: Unable to start activity, Unable to instantiate fragment, Error inflating class
body: <p>I'm brand new to Kotlin and I'm following a tutorial. Running my app causes it to crash on runtime. I have three fragments, and one main activity, in a bottom navigation bar app. My goal is really just to run the app successfully so I can try out Room databases, data binding and such concepts. I searched for possible reasons why it doesn't work with me but no luck. This is the current full error message:</p>
  <pre><code>    2021-02-27 14:58:23.967 23883-23883/com.jwanhsulaiman.talktag E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.jwanhsulaiman.talktag, PID: 23883
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jwanhsulaiman.talktag/com.jwanhsulaiman.talktag.MainActivity}: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class androidx.fragment.app.FragmentContainerView
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2919)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:280)
          at android.app.ActivityThread.main(ActivityThread.java:6706)
          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:858)
       Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class androidx.fragment.app.FragmentContainerView
       Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class androidx.fragment.app.FragmentContainerView
       Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.jwanhsulaiman.talktag.ui.home.HomeFragment: could not find Fragment constructor
          at androidx.fragment.app.Fragment.instantiate(Fragment.java:625)
          at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
          at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
          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:1059)
          at androidx.navigation.NavController.onGraphCreated(NavController.java:639)
          at androidx.navigation.NavController.setGraph(NavController.java:592)
          at androidx.navigation.NavController.setGraph(NavController.java:557)
          at androidx.navigation.NavController.setGraph(NavController.java:539)
          at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:248)
          at androidx.fragment.app.Fragment.performCreate(Fragment.java:2936)
          at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:472)
          at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:278)
          at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2177)
          at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2094)
          at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1959)
          at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:311)
          at androidx.fragment.app.FragmentContainerView.&lt;init&gt;(FragmentContainerView.java:176)
          at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:52)
          at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
          at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:313)
          at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:292)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
  2021-02-27 14:58:23.971 23883-23883/com.jwanhsulaiman.talktag E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
          at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
          at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
          at com.jwanhsulaiman.talktag.MainActivity.onCreate(MainActivity.kt:15)
          at android.app.Activity.performCreate(Activity.java:7136)
          at android.app.Activity.performCreate(Activity.java:7127)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:280)
          at android.app.ActivityThread.main(ActivityThread.java:6706)
          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:858)
       Caused by: java.lang.NoSuchMethodException: &lt;init&gt; []
          at java.lang.Class.getConstructor0(Class.java:2327)
          at java.lang.Class.getConstructor(Class.java:1725)
          at androidx.fragment.app.Fragment.instantiate(Fragment.java:610)
              ... 50 more
  </code></pre>
  <p>I've tried changing the XML file on line 21 (as per the error) from <code>fragment</code> to <code>androidx.fragment.app.FragmentContainerView</code> (as per Android Studio's suggestion upon hovering with mouse. I've tried adding dependencies but nothing seems to change to the better. I'll provide how my code looks like.</p>
  <p>MainActivity.kt (errors says it crashes on setContentView(R.layout.activity_main))</p>
  <pre><code>package com.jwanhsulaiman.talktag
  
  import android.os.Bundle
  import com.google.android.material.bottomnavigation.BottomNavigationView
  import androidx.appcompat.app.AppCompatActivity
  import androidx.navigation.findNavController
  import androidx.navigation.ui.AppBarConfiguration
  import androidx.navigation.ui.setupActionBarWithNavController
  import androidx.navigation.ui.setupWithNavController
  
  class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          val navView: BottomNavigationView = findViewById(R.id.nav_view)
  
          val navController = findNavController(R.id.nav_host_fragment)
          // Passing each menu ID as a set of Ids because each
          // menu should be considered as top level destinations.
          val appBarConfiguration = AppBarConfiguration(setOf(
                  R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
          setupActionBarWithNavController(navController, appBarConfiguration)
          navView.setupWithNavController(navController)
      }
  }
  </code></pre>
  <p>activity_main.xml</p>
  <pre><code>&lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout
      android:id=&quot;@+id/container&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:paddingTop=&quot;?attr/actionBarSize&quot;&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id=&quot;@+id/nav_view&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;0dp&quot;
          android:layout_marginEnd=&quot;0dp&quot;
          android:background=&quot;?android:attr/windowBackground&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:menu=&quot;@menu/bottom_nav_menu&quot; /&gt;
  
      &lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/nav_host_fragment&quot;
          class = &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:layout_constraintBottom_toTopOf=&quot;@id/nav_view&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:navGraph=&quot;@navigation/mobile_navigation&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  &lt;/layout&gt;
  </code></pre>
  <p>And the full snippet of HomeFragment in case it's related</p>
  <pre><code>    package com.jwanhsulaiman.talktag.ui.home
  
  import android.content.Context
  import android.os.Bundle
  import android.util.Log
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.TextView
  import androidx.databinding.DataBindingUtil
  import androidx.fragment.app.Fragment
  import androidx.lifecycle.Observer
  import androidx.lifecycle.ViewModelProvider
  import com.jwanhsulaiman.talktag.R
  import com.jwanhsulaiman.talktag.database.VocabData
  import com.jwanhsulaiman.talktag.database.VocabRepository
  import com.jwanhsulaiman.talktag.databinding.FragmentHomeBinding
  
  class HomeFragment(val applicationContext: Context) : Fragment() {
  
      private lateinit var homeViewModel: HomeViewModel
      private lateinit var binding: FragmentHomeBinding
  
      override fun onCreateView(
              inflater: LayoutInflater,
              container: ViewGroup?,
              savedInstanceState: Bundle?
      ): View? {
          homeViewModel =
                  ViewModelProvider(this).get(HomeViewModel::class.java)
          val root = inflater.inflate(R.layout.fragment_home, container, false)
          val textView: TextView = root.findViewById(R.id.text_home)
          homeViewModel.text.observe(viewLifecycleOwner, Observer {
              textView.text = it
          })
  
          binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
          val dao = VocabData.getInstance(this).VocabDao
          val repository = VocabRepository(dao)
          val factory = HomeViewModelFactory(repository)
          homeViewModel = ViewModelProvider(this, factory).get(HomeViewModel::class.java)
          binding.myViewModel = homeViewModel
          binding.lifecycleOwner = this
          displayVocabList()
  
          return binding.root
      }
  
      private fun displayVocabList() {
      homeViewModel.vocabs.observe(viewLifecycleOwner, Observer {
          Log.i(&quot;MYTAG&quot;, it.toString())
      })
  
      }
  }
  </code></pre>
  <p>Thanks for any insights!</p>