Reputation: 11453
I'm trying to use AndroidAnnotations @SharefPref
within kotlin, but Iget following error
org.androidannotations.annotations.sharedpreferences.Pref can only be used on an element that extends org.androidannotations.api.sharedpreferences.SharedPreferencesHelper
What am I doing wrong?
//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()
Upvotes: 4
Views: 925
Reputation: 518
I just wanna extend on @WonderCsabo 's answer. His answer almost saved me, but not fully.
After adding this to my app label build gradle.
kapt {
correctErrorTypes = true
}
I wasn't able to run my app.
Then I closed my android studio and then run Android studio again as administrator. Voila! it works like charm.
Thank you @WonderCsabo
Upvotes: 0
Reputation: 12207
This is due to a bug in the Kotlin annotation processor.
To fix this, you must add correctErrorTypes = true
to your kapt
block.
kapt {
correctErrorTypes = true
}
Also make sure you are using the latest Kotlin version (as of this moment: 1.1.3).
Upvotes: 5