首页 > 解决方案 > Android导航组件未解析参考

问题描述

我刚刚将平台从 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 canary 版本,但在开发人员网站上,导航组件没有任何变化。

我不确定它是 Mac 还是 Android Studio canary 6 错误。

任何帮助,将不胜感激!

标签: androidkotlinandroid-architecture-navigation

解决方案


findNavController: 有两种实现
public static NavController findNavController (View view)
public static NavController findNavController (Activity activity, int viewId)
但你使用

findNavController()  

你缺少所需的参数


推荐阅读