title: java.lang.IllegalStateException: Fragment already added: MovieFragment
body: <p>got error fragment already added on my MyPagerAdapter class which extends FragmentPagerAdapter</p>
  
  <p>this is my error logs</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: id.cahyowhy.tmdbmovieimplementation, PID: 8228
      java.lang.IllegalStateException: Fragment already added: MovieFragment{df79747} (01cf33b8-9eb3-4dce-9519-384ca7dd7570) id=0x7f08014e android:switcher:2131231054:0}
          at androidx.fragment.app.FragmentStore.addFragment(FragmentStore.java:67)
          at androidx.fragment.app.FragmentManager.addFragment(FragmentManager.java:1563)
          at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:405)
          at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2167)
          at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1990)
          at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1945)
          at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1847)
          at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
          at android.os.Handler.handleCallback(Handler.java:873)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:193)
          at android.app.ActivityThread.main(ActivityThread.java:6669)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
  </code></pre>
  
  <p>this is my pageradapter code</p>
  
  <pre><code>class MyPagerAdapter(fm: FragmentManager) :
      FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
  
      private val pages = listOf(
          MovieFragment.newInstance(MovieListType.POPULAR),
          MovieFragment.newInstance(MovieListType.TOP_RATED),
          MovieFragment.newInstance(MovieListType.UPCOMING)
      )
  
      override fun getItem(position: Int): Fragment {
          return pages[position]
      }
  
      override fun getCount(): Int {
          return pages.size
      }
  
      override fun getPageTitle(position: Int): CharSequence? {
          return when (position) {
              0 -&gt; "Popular"
              1 -&gt; "Top Rated"
              else -&gt; "Up Coming"
          }
      }
  }
  </code></pre>
  
  <p>this is my movie fragment code</p>
  
  <pre><code>package id.cahyowhy.tmdbmovieimplementation.ui.activity.fragment
  
  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 id.cahyowhy.tmdbmovieimplementation.databinding.MoviesFragmentResultBinding
  import id.cahyowhy.tmdbmovieimplementation.ui.adapter.ItemTypeFactoryImpl
  import id.cahyowhy.tmdbmovieimplementation.ui.adapter.VisitableRecyclerAdapter
  import id.cahyowhy.tmdbmovieimplementation.ui.adapter.viewholder.ErrorStateItem
  import id.cahyowhy.tmdbmovieimplementation.ui.adapter.viewholder.MovieItem
  import id.cahyowhy.tmdbmovieimplementation.ui.base.BaseFragment
  import id.cahyowhy.tmdbmovieimplementation.ui.base.BaseViewItem
  import id.cahyowhy.tmdbmovieimplementation.ui.util.ext.observe
  import org.koin.android.viewmodel.ext.android.viewModel
  
  open class MovieFragment(
      private val movieListType: MovieListType
  ) : BaseFragment() {
  
      private val viewModel by viewModel&lt;MovieFragmentViewModel&gt;()
  
      private lateinit var binding: MoviesFragmentResultBinding
  
      private val movieAdapter by lazy {
          VisitableRecyclerAdapter(
              ItemTypeFactoryImpl(),
              ::onItemClicked
          )
      }
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          binding = MoviesFragmentResultBinding.inflate(
              inflater,
              container,
              false
          )
  
          return binding.root
      }
  
      override fun onResume() {
          super.onResume()
          viewModel.loadData(0, movieListType)
      }
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          with(binding) {
              recyclerView.adapter = movieAdapter
              recyclerView.setHasFixedSize(true)
  
              swipeRefresh.setOnRefreshListener { viewModel.loadData(0, movieListType) }
          }
  
          super.onViewCreated(view, savedInstanceState)
      }
  
      override fun observeChange() {
          observe(viewModel.loading, ::handleLoading)
          observe(viewModel.movies, ::onDataLoaded)
          observe(viewModel.toastMessage, ::showSnackbarMessage)
      }
  
      private fun handleLoading(status: Boolean) {
          binding.swipeRefresh.isRefreshing = status
      }
  
      private fun onDataLoaded(items: List&lt;BaseViewItem&gt;) {
          movieAdapter.submitList(items)
      }
  
      private fun onItemClicked(viewItem: BaseViewItem, view: View) {
          when (viewItem) {
              is MovieItem -&gt; {
                  Log.d("MovieItem", "MovieItem Click: ${viewItem.title}")
              }
              is ErrorStateItem -&gt; {
                  viewModel.loadData(0, movieListType)
              }
          }
      }
  
      companion object {
          fun newInstance(movieListType: MovieListType): MovieFragment =
              MovieFragment(movieListType)
      }
  }
  
  </code></pre>
  
  <p>and this is when i called from MainActivity.kt</p>
  
  <pre><code>class MainActivity : BaseActivity() {
      private lateinit var binding: ActivityMainBinding;
  
      ....
  
      fun initView() {
          with(binding) {
              viewPager.adapter = MyPagerAdapter(supportFragmentManager)
              viewPagerTab.setupWithViewPager(viewPager)
          }
      }
  </code></pre>
  
  <p>can anyone solve this.. thanks..</p>