如何解决此 Android SQLite Room DAO 错误消息?
How to solve this Android SQLite Room DAO error message?
我不知道下面的问题是怎么回事?
代码:
CategoryDAO.kt
@Dao
interface CategoryDAO {
@Query("select * from CategoryDesign")
suspend fun getCategory(): MutableLiveData<List<CategoryDesign>>
}
CategoryDesign.kt
@Entity
data class CategoryDesign (
@PrimaryKey
var categoryDesignID:String,
var designImage:String,
var designTitle:String){
constructor() : this("","","")
override fun toString(): String {
return designTitle
}
}
按 运行 应用程序按钮将显示如下错误:
error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.MutableLiveData<java.util.List<com.squall.searchdesigner.model.CategoryDesign>>).
public abstract java.lang.Object getCategory(@org.jetbrains.annotations.NotNull()
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC), android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC).
依赖项:
dependencies {
def room_version = "2.2.3"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
}
好像只能使用LiveData return类型。也许 Room 不允许您使用 MutableLiveData?
谢谢大家。
我使用下面的代码重建项目并使缓存无效似乎解决了这个问题。
@Dao
interface CategoryDAO {
@Query("select * from CategoryDesign")
fun getCategory(): LiveData<MutableList<CategoryDesign>>
}
我不知道下面的问题是怎么回事?
代码:
CategoryDAO.kt
@Dao
interface CategoryDAO {
@Query("select * from CategoryDesign")
suspend fun getCategory(): MutableLiveData<List<CategoryDesign>>
}
CategoryDesign.kt
@Entity
data class CategoryDesign (
@PrimaryKey
var categoryDesignID:String,
var designImage:String,
var designTitle:String){
constructor() : this("","","")
override fun toString(): String {
return designTitle
}
}
按 运行 应用程序按钮将显示如下错误:
error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.MutableLiveData<java.util.List<com.squall.searchdesigner.model.CategoryDesign>>).
public abstract java.lang.Object getCategory(@org.jetbrains.annotations.NotNull()
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC), android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC).
依赖项:
dependencies {
def room_version = "2.2.3"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
}
好像只能使用LiveData return类型。也许 Room 不允许您使用 MutableLiveData?
谢谢大家。 我使用下面的代码重建项目并使缓存无效似乎解决了这个问题。
@Dao
interface CategoryDAO {
@Query("select * from CategoryDesign")
fun getCategory(): LiveData<MutableList<CategoryDesign>>
}