File Crime.kt
@Entity
data class Crime (@PrimaryKey val id: UUID = UUID.randomUUID(),
var title: String = "",
var date: Date = Date(),
var isSolved: Boolean = false)
File CrimeTypeConverters.kt
class CrimeTypeConverters {
@TypeConverter
fun fromDate(date: Date?): Long?{
return date?.time
}
@TypeConverter
fun toDate(millisSinceEpoch: Long?): Date? {
return millisSinceEpoch?.let {
Date(it)
}
}
@TypeConverter
fun toUUID(uuid: String?): UUID? {
return UUID.fromString(uuid)
}
@TypeConverter
fun fromUUID(uuid: UUID?): String? {
return uuid?.toString()
}
}
error :
error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.
private java.util.Date date;
C:\Users\ASUS\AndroidStudioProjects\CriminalIntentv2\app\build\tmp\kapt3\stubs\debug\com\bignerdranch\android\criminalintent\database\CrimeDatabase.java:8: warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide room.schemaLocation
annotation processor argument OR set exportSchema to false.
public abstract class CrimeDatabase extends androidx.room.RoomDatabase {
^[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (NON_INCREMENTAL).
Task :app:kaptDebugKotlin FAILED
@TypeConverters
annotation to point Room to your@TypeConverter
? – CommonsWare