【问题标题】:How to solve this Android SQLite Room DAO error message?如何解决此 Android SQLite Room DAO 错误消息?
【发布时间】:2020-01-13 09:18:21
【问题描述】:

我不知道下面的问题有什么问题?

代码:

CategoryDAO.kt

@Dao
interface CategoryDAO {
    @Query("select * from CategoryDesign")
    suspend fun getCategory(): MutableLiveData<List<CategoryDesign>>


}

CategoryDe​​sign.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"
}

【问题讨论】:

  • 您可以添加您的CategoryDesign 实体吗?
  • 你在使用分页库吗?
  • @Md. Asaduzzaman 我添加了 CategoryDe​​sign 实体。
  • @Raghunandan 我使用 ViewPager 和 RecyclerView

标签: android android-sqlite android-room dao


【解决方案1】:

您似乎只能使用 LiveData 返回类型。也许 Room 不允许你使用 MutableLiveData?

【讨论】:

    【解决方案2】:

    谢谢大家。 我使用下面的代码并重建项目并使缓存无效似乎解决了这个问题。

    @Dao
    interface CategoryDAO {
        @Query("select * from CategoryDesign")
        fun getCategory(): LiveData<MutableList<CategoryDesign>>
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2014-12-24
      • 2020-07-29
      • 2018-04-19
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多