片段和Anko吐司的“接收器类型不匹配" [英] 'receiver type mismatch' with Fragment and Anko toast
本文介绍了片段和Anko吐司的“接收器类型不匹配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Jetbrains的Anko库在我的应用程序中轻松显示Android Toast消息.
I am trying to use Jetbrains' Anko library to easily display an Android toast message in my app.
这是相关的代码段:
val message : CharSequence = "Recycled: ${holder.taskEditText.text}"
(tasksFragment as Fragment).toast(text = message)
和错误:
Error:(80, 45) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun Fragment.toast(text: CharSequence): Unit defined in org.jetbrains.anko
public inline fun Fragment.toast(textResource: Int): Unit defined in org.jetbrains.anko
public fun Context.toast(text: CharSequence): Unit defined in org.jetbrains.anko
public fun Context.toast(textResource: Int): Unit defined in org.jetbrains.anko
public inline fun AnkoContext<*>.toast(text: CharSequence): Unit defined in org.jetbrains.anko
public inline fun AnkoContext<*>.toast(textResource: Int): Unit defined in org.jetbrains.anko
对于Kotlin来说,我还很陌生,并且一段时间以来一直在寻找解决方案.感谢所有帮助.
I am pretty new to Kotlin and have been searching for a solution to this issue for a while. All help is appreciated.
推荐答案
由于错误提示所有错误均不适用,因此您可能导入了与Android/Support Library定义的类不同的Fragment
类.
Since the error says none are applicable you've probably imported a different Fragment
class than the one defined by Android/Support Library.
检查您的进口.
这篇关于片段和Anko吐司的“接收器类型不匹配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文