android - FragmentDirections 不是由 Safe Args 插件生成的
问题描述
当我尝试使用 Safe Args 插件从一个片段跳转到另一个片段时,编译器显示“未解析的参考:VideoFragmentDirections”。我已经为安全参数设置了类路径和依赖项,并且 VideoFragmentArgs 已正确生成。kotlin_version = '1.3.50' navigation-safe-args-gradle-plugin:2.1.0 在我的 xml
<fragment
android:id="@+id/nav_home"
android:name="example.ui.home.HomeFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_nav_home_to_videoFragment"
app:destination="@id/videoFragment"
app:popUpTo="@+id/nav_home"/>
</fragment>
<fragment
android:id="@+id/videoFragment"
android:name="example.ui.videoui.VideoFragment"
android:label="VideoFragment" >
<argument
android:name="id"
app:argType="long"
android:defaultValue="0L" />
</fragment>
在 HomeFragment.ky 中
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val videoViewModel = ViewModelProviders
.of(this)
.get(HomeViewModel::class.java)
val adapter = video_list.adapter!! as PlaylistAdapter
videoViewModel.videos.observe(this, Observer<List<Video>> {
adapter.submitList(it)
adapter.onItemClickListener = View.OnClickListener { v ->
val viewHolder = v.tag as RecyclerView.ViewHolder
val position = viewHolder.adapterPosition
val id = it[position].id
val action = VideoFragmentDirections.actionhHomeToVideo(id)
view.findNavController().navigate(action)
}
})
}
此外,我曾尝试清理和重建项目,它仍然无法正常工作。
解决方案
尝试
apply plugin: "androidx.navigation.safeargs.kotlin"
在应用程序 build.gradle
推荐阅读
- laravel - 标签 [Charts_assets] 没有可发布的内容
- android - android.content.Context.getSystemService(java.lang.String)' 在空对象引用 Retrofit
- regex - C++ std::regex 分段错误
- javascript - 为什么让 a = [{}] 和 a.indexOf({}) -1?
- powershell - 无法将参数绑定到参数“名称”,因为它是一个空字符串
- bazel - 如何不在每次调用时重建工件
- javascript - 无法在 Skype WebChat 上加载资源
- c# - 有没有一种方法可以简化 ViewModel 中的属性定义?
- html - 表格列中相同宽度的单元格?
- excel - Series.Format.Fill.Transparency 属性不应用格式