0

我試圖使用AndroidAnnotations科特林內@SharefPref,但下面的錯誤如何使用AndroidAnnotation @SharedPref與科特林

org.androidannotations.annotations.sharedpreferences.Pref can only be used on an element that extends org.androidannotations.api.sharedpreferences.SharedPreferencesHelper 

我在做什麼錯的iget?

//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() 
+1

錯誤信息不是不言自明嗎? 'MyPreferences'不擴展'SharedPreferencesHelper'。 – azizbekian

+0

@azizbekian不,它不是。使用'Kotlin'和'Annotations'有時會引發與實際問題無關的錯誤。如果註釋代碼被生成,則會發生這種情況。 (請參閱下面的解決方案) – longilong

回答

0

這是由於Kotlin註釋處理器中的bug
若要解決此問題,請將you must addcorrectErrorTypes = true與您的kapt區塊對齊。

kapt { 
    correctErrorTypes = true 
} 

另外,還要確保你使用的是最新版本的科特林(因爲這一刻的:1.1.3)。

+0

我在android註釋中發現了固定的錯誤報告,但它沒有告知添加'correctErrorTypes'(https://github.com/androidannotations/androidannotations/issues/334)謝謝! – longilong

+0

你發現了錯誤的問題,它在2012年被報道。:) – WonderCsabo

+0

:D omg ...休息和啤酒的時間我猜.... – longilong