三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

Android 开发 Navigation 问题:cannot be found from the current destination Destination

Android 开发 Navigation 问题:cannot be found from the current destination Destination
NavOptionsnavOptions=newNavOptions.Builder().setPopUpTo(R.id.XXX,true).build();navController.navigate(R.id.XXX,null,navOptions);
  • 在 Android 开发中,使用 Navigation 时,出现如下错误信息
java.lang.IllegalArgumentException: XXX cannot be found from the current destination Destination XXX
问题原因
  1. Navigation 跳转时(调用 navigate 方法时),指定的 action 在当前目标中不存在

  2. 这个错误通常发生在这个导航 action 不属于当前所在的 Fragment,误用了其他 Fragment 的 action

处理策略
  • 确保调用 navigate 方法时,指定的 action 是当前 Fragment 中的 action
← 返回列表