0

I am getting this error:

error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :network.
error: Unused parameter: arg0

when trying Room and Kotlin like this:

@Dao
interface TokenDefinitionDao {

    @Query("SELECT * FROM token_descriptors WHERE network LIKE :network")
    fun getAllForNetwork(network: String?): List<TokenDescriptor>

    @Delete
    fun delete(token: TokenDescriptor)
}

But I am passing and using this parameter. Anyone sees what the problem is or can point me to working examples of using Room with Kotlin?

ligi
  • 39,001
  • 44
  • 144
  • 244

2 Answers2

5

Try to change "network" param to "arg0"

@Query("SELECT * FROM token_descriptors WHERE network LIKE :arg0")

In newer versions of kotlin and room this issue was fixed!

Fredy Mederos
  • 2,506
  • 15
  • 13
4

To avoid that problem you have to use kotlin-kapt plugin in your build.gradle.

...

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

...

android {
...
}

btw, ensure that you're using kotlin 1.2.0+

0wl
  • 836
  • 8
  • 19