lon*_*ngi 4 android kotlin android-annotations kotlin-android-extensions
我正在尝试@SharefPref在 kotlin 中使用AndroidAnnotations,但出现以下错误
org.androidannotations.annotations.sharedpreferences.Pref can only be used on an element that extends org.androidannotations.api.sharedpreferences.SharedPreferencesHelper
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
//Interface
@SharedPref(SharedPref.Scope.APPLICATION_DEFAULT)
open interface MyPreferences {
@DefaultInt(-1)
fun someIntValue():Int
}
//Fragment
@Pref
lateinit open var sharedPref:CongressPreferences_
//usage within fragment
val get: Int = sharedPref.selectedEventId().get()
Run Code Online (Sandbox Code Playgroud)
这是由于Kotlin 注释处理器中的错误造成的。
要解决此问题,您必须添加 correctErrorTypes = true到kapt块中。
kapt {
correctErrorTypes = true
}
Run Code Online (Sandbox Code Playgroud)
还要确保您使用的是最新的 Kotlin 版本(截至目前:1.1.3)。
| 归档时间: |
|
| 查看次数: |
789 次 |
| 最近记录: |