小编chr*_*scz的帖子

Android Room:查询中的每个绑定变量都必须具有匹配的方法

我正在使用带有kotlin的android持久性库房间.

Dao看起来像这样

@Dao
interface CountryDao {
    @Query("SELECT * FROM countries")
    fun loadAllCountried() : LiveData<List<CountryEntity>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(products: List<CountryEntity>)

    @Query("SELECT * FROM countries WHERE id = :countryId")
    fun loadCountry(countryId: Int): LiveData<CountryEntity>

    @Query("SELECT * FROM countries WHERE id = :countryId")
    fun loadCountrySync(countryId: Int): CountryEntity

}
Run Code Online (Sandbox Code Playgroud)

这对我来说似乎很好,但我收到了这个错误

Error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :countryId.

我可以看到参数被命名为countryId,那么可能是什么问题?

仅供参考:这是CountryDao_Impl.java中的生成代码

@Override
public CountryEntity loadCountrySync(int arg0) {
  final String _sql = "SELECT …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-room

29
推荐指数
4
解决办法
6152
查看次数

标签 统计

android ×1

android-room ×1

kotlin ×1