An Annotation argument must be a compile time constant

…衆ロ難τιáo~ 提交于 2019-12-01 18:08:56

The problem is the one stated in the error, you can't have dynamically defined arguments for your @Query annotation. If you want to define the name of the table somewhere else, use string concatenation. You can do it like this:

@Query("SELECT * FROM " + Table.USER_TABLE)
fun getAll(): List<User>

This is how they do it in this google sample.

You should define column name also in data class and access if you want to use columns in queries and access it via this method:

@Query("SELECT * FROM ${Table.USER_TABLE}")

try put a "\" before "$"

@Query("SELECT * FROM \$Table.USER_TABLE")
fun getAll(): List<User>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!