I have a project with a Room database, which was working fine, and now for some reason I can't find out, it isn't anymore.
I am getting the following error when compiling:
C:\(...)\FlightDao.java:18: error: Not sure how to convert a Cursor to this method's return type (java.lang.Object).
public abstract java.lang.Object getFlightById(int id, @org.jetbrains.annotations.NotNull()
This is from a class that is generated from my Dao
:
@Dao
interface FlightDao {
@Query("SELECT * FROM FlightData WHERE DELETEFLAG == 0 AND flightID = :id LIMIT 1")
suspend fun getFlightById(id: Int): FlightData?
}
Now, if I change the function to not suspend
, return a Flow and get its first result, it doesnt give an error. But, according to documentation I should do it the way I did, as it is a one-shot operation.
My gradle file has these (entire file here):
apply plugin: 'kotlin-kapt'
(...)
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
and now I am at a loss for why this isn't working. Only things I find are about suspend not being compatible with LiveData, but I don't use LiveData. As far as I can tell, I did it exactly as in the documentation. Anybody has any ideas? (I did try clean and rebuild)
Kotlin version 1.7.0
Room version 2.4.2
CodePudding user response:
try to delete ? in FlightData for null safety
second notice you must write query for condition with one equal sign not twice like programming
use this
@Query("SELECT * FROM FlightData WHERE DELETEFLAG = 0 AND flightID = :id LIMIT 1")
CodePudding user response:
I fixed this by switching from kapt
to ksp
(link)
Still not a clue why kapt didn't want to do it anymore, but meh, it works now :)
new gradle:
plugins {
id 'com.google.devtools.ksp' version '1.7.0-1.0.6'
}
(...)
dependencies {
implementation "androidx.room:room-runtime:$room_version"
ksp "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
(...)
}