0
votes

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

1
Where do you have your @TypeConverters annotation to point Room to your @TypeConverter?CommonsWare
BTW, UUID as id is usually a bad practice, if you just want convenience: @PrimaryKey(autoGenerate = true)Frischling

1 Answers

0
votes

Did you link the converters with your database

@Database(
    entities = [
        Crime::class, ...
    ]
)
@TypeConverters(
    //...
    CrimeTypeConverters::class
)
abstract class CrimeDatabase : RoomDatabase() {
   //...
}

You can take a look at the documentation, there is a way to use it on entity case by case, but I can't find a reference now.

I think the keywords that tells the problem are:

...Cannot figure out how to save this field into database. You can consider adding a type converter for it. ...\CrimeDatabase.java:8: warning: Schema export directory is not provided to the annotation processor...