kotlin - “推断类型是 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)
解决方案
该方法被注释为 Nullable。改成这样
fragmentManager?.let { manager ->
bottomDialog.newInstance(//options here
).show(manager, bottomDialog.TAG)
}
推荐阅读
- html - 在某些手机上,导航栏无法覆盖整个页面宽度
- c# - 尝试在 Web API Core 中使用 EF Core 在启动时更新数据库时出现“'无法访问已处置的对象”错误
- javascript - 如何捕获错误:在 TCPConnectWrap.afterConnect 处连接 ECONNREFUSED [as oncomplete]
- orchestration - 如何通过 Orchestrator 在 Service Manager 中动态添加手动活动?
- json - 如何克服 Snowflake Varchar (16,777,216) 加载图像数据的限制
- javascript - 使用 chartjs、mongodb 和控制器的图表的前端和后端
- typescript - 异步函数永不抛出的意义何在?
- javascript - 在电子浏览器窗口中多次打开模态
- python - 如何在windows中获取python进程的PID
- java - 手动关闭和打开android应用程序的等效编程代码是什么?