BottomsheetDialogFragment 的子片段在第二次尝试打开后崩溃

Child fragment of BottomsheetDialogFragment crashes after second attempt opening

我有一个片段,它是 BottomsheetDialogFragment 的子片段,在该片段中我有一个 google 映射。起初,当我使用 arch components NavController 打开此片段时,它工作正常,如果我关闭此片段并尝试再次打开它,它会崩溃。 这是错误日志

Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #71 in com.example.com:layout/product_location_fragment: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #71: Duplicate id 0xffffffff, tag mapFragment, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
    at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:116)

这是片段本身

  class ProductLocationFargment : BottomSheetDialogFragment, {


  override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
  ): View? {
    return inflater.inflate(R.layout.product_location_fragment, container, false)
  }

  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    //this also always returns null
    val frag = childFragmentManager.findFragmentById(R.id.mapFragment) as? SupportMapFragment

  }

}

和布局xml

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
        android:layout_height="match_parent">

      <fragment
        android:tag="mapFragment"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        app:layout_constraintStart_toStartOf="@id/leftGuideView"
        app:layout_constraintEnd_toEndOf="@id/rightGuideView" />


    </androidx.constraintlayout.widget.ConstraintLayout>

这就是我从另一个片段开始那个片段的方式

button.setOnClickListener {
  val direction = AnotherFragmentDirections.actionAnotherFragmentToProductLocationFargment()
  navController.navigate(direction)
}

尝试手动将 mapFragment 添加到 FrameLayout 而不是使用 <fragment 标签,但前提是 if(savedInstanceState == null) { 否则通过标签

获取它