首页 > 解决方案 > “推断类型是 FragmentManager?但 FragmentManager 是预期的”移动到 androidX 后出现错误

问题描述

我刚刚将我的项目移至 androidX。我使用 android studio 重构->升级到 androidX。TargetSDK 已经 28 岁并且工作正常。所以没想到会有很多错误。但我错了,得到了很多错误,其中大部分是关于 fragmentManager

inferred type is FragmentManager? but FragmentManager was expected

这是我在片段中调用自定义 bottomSheetDialogue 的 show 方法时。

bottomDialog.newInstance(//options here
                  ).show(fragmentManager, bottomDialog.TAG)

标签: kotlinandroidxfragmentmanager

解决方案


该方法被注释为 Nullable。改成这样

fragmentManager?.let { manager ->
    bottomDialog.newInstance(//options here
              ).show(manager, bottomDialog.TAG)
}

推荐阅读