与Fragment和Anko吐司的“接收器类型不匹配”
我正尝试使用Jetbrains的Anko库在我的应用程序中轻松显示Android Toast消息。
这里是相关的代码片段:
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相当陌生,一直在寻找这个问题的解决方案。 所有的帮助表示赞赏。
由于错误说没有适用的,你可能已经导入了一个不同于Android / Support Library定义的Fragment
类。
检查你的进口。
- SimpleXML在Thread.getContextClassLoader()返回的类加载器可能失败之后抛出ClassNotFoundException
- 无法解析:用于电话号码身份验证的com.google.firebase:firebase-auth:11.0.2
- IntentService(kotlin)的默认构造函数
- Android ClassNotFoundException在路径上找不到类:DexPathList
- 访问android.os.storage.StorageVolume
- 财产必须被初始化或是抽象的
- 有问题从fragmentManager / MapFragment移动到supportfragmentManager / SupportMapFragment
- getFragmentManager()不在Kotlin中工作
- 如何使Android Studio实时检查了解@ParametersAreNonnullByDefault?