title: How to find a view for Snackbar in fragment's onCreateView method if I use view binding and navigation component?
body: <p>I'm trying to show a snack bar in fragment's onCreateView method but I don't know what view to passing inside the snack bar.
  I'm very confused because I first time use the Navigation component and view binding and maybe is there a problem.
  I tried binding.root but I got this exception:</p>
  <blockquote>
  <p>java.lang.IllegalArgumentException: No suitable parent found from the
  given view. Please provide a valid view.</p>
  </blockquote>
  <p>After that I tried requireView().rootView as parameter but I also got this exception:</p>
  <blockquote>
  <p>java.lang.IllegalStateException: Fragment XFragment{7a091b5}
  (cefa1aef-59c3-4602-bcf1-b36f7d538cf9) id=0x7f0800f7} did not return a
  View from onCreateView() or this was called before onCreateView()</p>
  </blockquote>
  <p>MY CODE IN XFragment:</p>
  <pre><code>package com.sdsd.sds
  
  import android.os.Bundle
  import androidx.fragment.app.Fragment
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import androidx.navigation.Navigation
  import com.google.android.material.snackbar.Snackbar
  
  import com.sdsd.sds.databinding.FragmentXBinding
  
  private const val ARG_PARAM1 = &quot;param1&quot;
  private const val ARG_PARAM2 = &quot;param2&quot;
  
  
  class XFragment : Fragment() {
  
      private var _binding: FragmenXBinding? = null
      private val binding get() = _binding!!
  
  
      private var param1: String? = null
      private var param2: String? = null
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          arguments?.let {
              param1 = it.getString(ARG_PARAM1)
              param2 = it.getString(ARG_PARAM2)
          }
  
      }
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          _binding = FragmentXBinding.inflate(inflater, container, false)
          binding.tvFgRegistration.setOnClickListener {
              Navigation.findNavController(binding.root)
                  .navigate(R.id.action_f1_to_f2)
          }
  
          
  
          val snackbar: Snackbar = Snackbar.make(binding.root, &quot;Succesful&quot;, Snackbar.LENGTH_LONG)
          snackbar.show()
  
  
          return binding.root
      }
  
      override fun onDestroyView() {
          super.onDestroyView()
          _binding = null
      }
  
  
      companion object {
  
          @JvmStatic
          fun newInstance(param1: String, param2: String) =
              XFragment().apply {
                  arguments = Bundle().apply {
                      putString(ARG_PARAM1, param1)
                      putString(ARG_PARAM2, param2)
                  }
              }
      }
  }
  
  XML LAYOUT FILE:
  
      &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
      &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
          xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
          xmlns:tools=&quot;http://schemas.android.com/tools&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:background=&quot;@drawable/ic&quot;
          tools:context=&quot;.XFragment&quot;&gt;
      
         
          &lt;EditText
              android:id=&quot;@+id/etE&quot;
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginStart=&quot;16dp&quot;
              android:layout_marginTop=&quot;24dp&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              android:background=&quot;@color/translucent&quot;
              android:drawableStart=&quot;@drawable/ic_vector&quot;
              android:drawablePadding=&quot;5dp&quot;
              android:ems=&quot;10&quot;
              android:hint=&quot;@string/e_mail&quot;
              android:inputType=&quot;text&quot;
              android:textSize=&quot;25sp&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintHorizontal_bias=&quot;0.0&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/imageView&quot; /&gt;
      
          &lt;EditText
              android:id=&quot;@+id/etP&quot;
              android:layout_width=&quot;0dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginStart=&quot;16dp&quot;
              android:layout_marginTop=&quot;24dp&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              android:background=&quot;@color/translucent&quot;
              android:drawableStart=&quot;@drawable/ic_vector&quot;
              android:drawablePadding=&quot;5dp&quot;
              android:ems=&quot;10&quot;
              android:hint=&quot;@string/password&quot;
              android:inputType=&quot;textPassword&quot;
              android:textSize=&quot;25sp&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintHorizontal_bias=&quot;0.0&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/etE&quot; /&gt;
      
            
          &lt;TextView
              android:id=&quot;@+id/tvFgRegistration&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginStart=&quot;180dp&quot;
              android:layout_marginEnd=&quot;76dp&quot;
              android:layout_marginBottom=&quot;100dp&quot;
              android:text=&quot;@string/new_u&quot;
              android:textColor=&quot;@color/white&quot;
              android:textSize=&quot;18sp&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot; /&gt;
      
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>I only want to show a snack bar with a message when XFragment creates.</p>
  <p><strong>Can anyone tell me how to solve this and explain me in a few words why?</strong></p>