Room 和 Kotlin - 获得 "Each bind variable in the query must have a matching method parameter."
Room and Kotlin - getting "Each bind variable in the query must have a matching method parameter."
我收到这个错误:
error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :network.
error: Unused parameter: arg0
像这样尝试 Room 和 Kotlin 时:
@Dao
interface TokenDefinitionDao {
@Query("SELECT * FROM token_descriptors WHERE network LIKE :network")
fun getAllForNetwork(network: String?): List<TokenDescriptor>
@Delete
fun delete(token: TokenDescriptor)
}
但是我正在传递和使用这个参数。任何人都知道问题出在哪里,或者可以向我指出将 Room 与 Kotlin 结合使用的工作示例吗?
为避免该问题,您必须在 build.gradle 中使用 kotlin-kapt 插件。
...
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
...
android {
...
}
顺便说一句,确保您使用的是 kotlin 1.2.0+
尝试将 "network" 参数更改为 "arg0"
@Query("SELECT * FROM token_descriptors WHERE network LIKE :arg0")
在较新版本的 kotlin 和 room 中,此问题已得到修复!
我收到这个错误:
error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :network.
error: Unused parameter: arg0
像这样尝试 Room 和 Kotlin 时:
@Dao
interface TokenDefinitionDao {
@Query("SELECT * FROM token_descriptors WHERE network LIKE :network")
fun getAllForNetwork(network: String?): List<TokenDescriptor>
@Delete
fun delete(token: TokenDescriptor)
}
但是我正在传递和使用这个参数。任何人都知道问题出在哪里,或者可以向我指出将 Room 与 Kotlin 结合使用的工作示例吗?
为避免该问题,您必须在 build.gradle 中使用 kotlin-kapt 插件。
...
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
...
android {
...
}
顺便说一句,确保您使用的是 kotlin 1.2.0+
尝试将 "network" 参数更改为 "arg0"
@Query("SELECT * FROM token_descriptors WHERE network LIKE :arg0")
在较新版本的 kotlin 和 room 中,此问题已得到修复!