Android Room - error: Cannot figure out how to save this field into database

前端 未结 3 1603
清酒与你
清酒与你 2020-12-16 19:22

Detailed log

error: Cannot figure out how to save this field into database. You can 
consider adding a type converter for it.
private final java.util.Date m         


        
3条回答
  •  别那么骄傲
    2020-12-16 20:05

        // Java code will not convert to Kotlin very 
        // well so here is the Kotlin: Converter 
        // class
    
        public class Converters {
            @TypeConverter
            fun fromTimestamp( value: Long?) : 
                           java.sql.Date {
                return java.sql.Date(value ?: 0)
            }
            @TypeConverter
            fun dateToTimestamp(date :java.sql.Date?) 
                                     :Long {
                return date?.getTime() ?: 0
           }
    
        // Here is the type converters example in 
        // Kotlin
        @Database(entities = [DbNasaPictures::class], 
                  version = 2)
        @TypeConverters(Converters::class)
        abstract class PicturesDatabase: 
                         RoomDatabase() {
    

提交回复
热议问题