启用safe-args插件后无法从数据绑定获取根视图 [英] Can't get Root View from Data Binding after enabling safe-args plugin
问题描述
我正在使用dataBinding在Android应用程序上工作,当前正在尝试添加safe-args插件,但是启用该插件后,我无法再通过binding.root获取根视图-Android Studio给出了错误消息:
I'm working on an Android app using dataBinding and am currently trying to add the safe-args plugin, but after enabling the plugin, I can no longer get the root view via binding.root - Android Studio gives the error:
Unresolved Reference
None of the following candidates is applicable because of a receiver type mismatch:
* internal val File.root: File defined in kotlin.io
如何使数据绑定和safe-args一起玩得开心?
How can I get databinding and safe-args to play nice together?
请注意,虽然代码片段位于Kotlin中,但我会很高兴获得Java答案.对Java不太满意,但我可以轻松阅读并翻译.
Note that while the code snippet is in Kotlin I will happily take Java answers. Not as comfortable in Java but I can easily read it and translate it.
我无法通过谷歌搜索错误消息和安全参数"来找到其他遇到相同问题的人.我首先尝试使用以下Android文档中列出的类路径: https://developer. android.com/guide/navigation/navigation-pass-data
I haven't been able to find anyone else with the same problem by Googling the error message and "safe args". I tried first with the classpath listed in the Android docs here: https://developer.android.com/guide/navigation/navigation-pass-data
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0"
然后还找到了一个建议我使用的教程:
And then also found a tutorial suggesting I use:
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07"
两者都有相同的问题:binding.root在激活插件时出现错误
Both had the same issue: binding.root gave an error with the plugin activated
这是我的片段的onCreateView().该返回行在未启用safe-args时正常工作,而在启用后则不起作用
Here is my onCreateView() for my fragment. That return line works properly when safe-args isn't enabled and doesn't work when it is enabled
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_encoder, container, false)
return binding.root
}
对于解决或理解此问题的任何帮助,深表感谢!
Any help solving or understanding this problem is most appreciated!
推荐答案
我遇到了同样的问题, 对我来说是如此有线 但只要重命名布局即可再次使用, 尝试:D
I have the same issue, it's so wired for me, but just rename the layout will work again, try to it :D
这篇关于启用safe-args插件后无法从数据绑定获取根视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!