我刚从Windows平台转换到Mac平台,在尝试构建我的应用程序时,出现了以下消息:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun `Activity;`.findNavController(viewId: Int): `NavController;` defined in androidx.navigation
public fun `View;`.findNavController(): `NavController;` defined in androidx.navigation
错误在那行代码里:
bSettingsLogout.findNavController().navigate(R.id.authenticationActivity)
在Windows上,我使用的是旧版本的3.3金丝雀版,但在开发者网站上,导航组件方面没有任何变化。我不确定这是否是Mac或Android Studio金丝雀版6的错误。任何帮助将不胜感激!
Navigation.findNavController(myActivity, R.id.nav_host)
。 - user8959091fun View.findNavController(): NavController = Navigation.findNavController(this)
,这意味着您只需在“View”对象上调用findNavController()
,而不是将“View”传递给静态函数。 - Ben Ezard