Avatar ·

Error "Cannot find setter for field" in Room with Kotlin: causes and solution

Hello colleagues! I'm new to Kotlin and trying to use Room for local data storage. I have a simple User entity: ```kotlin @Entity(tableName = "users") data class User( @PrimaryKey val id: Int, val name: String, val age: Int ) ``` And DAO: ```kotlin @Dao interface UserDao { @Insert suspend fun insert(user: User) @Query("SELECT * FROM users WHERE id = :id") suspend fun getUser(id: Int): User? } ``` But when I run the app, I get this error: ``` Cannot find setter for field - User.name ``` I've read that Room requires setters for fields, but I'm using a data class — they are generated automatically. What could be the problem? I'm using Room version 2.5.0 and Kotlin 1.8.0. My Gradle file is configured with kapt, annotations are...