title: Kotlin how to set tablayout inside fragment (viewpager is not working)
body: <p>i am trying to create <code>tablayout</code> inside fragment. for some reason my <code>viewpager</code> is not working properly. it keep showing same error as below</p>
  
  <p><a href="https://i.stack.imgur.com/IPl1F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IPl1F.png" alt="enter image description here"></a></p>
  
  <p>my fragment codes and xml files are below</p>
  
  <pre><code>package com.example.rsquare_android_fixed.mywork.building
  
  import android.os.Bundle
  import android.util.Log
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import androidx.fragment.app.Fragment
  import androidx.viewpager.widget.ViewPager
  import com.example.rsquare_android_fixed.R
  import kotlinx.android.synthetic.main.fragment_mywork.*
  
  
  class MWFragment: Fragment(){
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          //val view=inflater.inflate(R.layout.fragment_mywork, container, false)
  
          Log.d("test","test")
  
          //vp_main.adapter=MW_Adapter(childFragmentManager)
          val fa=MW_Adapter(childFragmentManager)
          vp_main.adapter=fa
          tab_layout.setupWithViewPager(vp_main)
  
          return inflater.inflate(R.layout.fragment_mywork, container, false)
      }
  
  }
  </code></pre>
  
  <p><strong>xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:theme="@style/TabTheme"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
          &lt;com.google.android.material.tabs.TabLayout
              android:id="@+id/tab_layout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"/&gt;
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
      &lt;androidx.viewpager.widget.ViewPager
          android:id="@+id/vp_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical"
          android:text="hi"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <blockquote>
    <p>but if i try same codes on mainactivity it works well ...</p>
  </blockquote>