我需要从set
获得RoomDatabase
的字符串
实体:
@Entity
data class Data(
@PrimaryKey val id: Int,
val type: String,
val photo: String
)
我需要获取set
的类型。我尝试遵循方法:
...
@Query("SELECT type FROM data")
fun getAllTypes(): LiveData<Set<String>>
...
现在我有下一个错误:
C:\...\storage\DataDao.java:24: error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.LiveData<java.util.Set<java.lang.String>>).
public abstract androidx.lifecycle.LiveData<java.util.Set<java.lang.String>> getAllTypes();
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
> Task :app:kaptDebugKotlin FAILED
答案 0 :(得分:1)
抱歉,您无法获得Set。根据SELECT查询的文档,您只能使用List或Array。
https://developer.android.com/reference/androidx/room/Query
如果需要独特的物品,可以使用SQL的DISTINCT。
答案 1 :(得分:0)
也许是这样
@Query("SELECT type FROM data")
必须是这样:
@Query("SELECT type FROM Data")