当我尝试将ArrayList<Float>
另存为会议室数据库中的列时出错
@Entity(tableName = "Height")
class Height: Serializable {
@PrimaryKey(autoGenerate = true)
var id: Long = 0
@ColumnInfo(name = "data")
var data: ArrayList<Float>? = ArrayList()
}
@Dao
abstract class HeightDao : BaseDao<Height>() {
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertAllHeight(listOfHeight: ArrayList<Float>)
我写了TypeConverter
@TypeConverter
fun fromArrayListOfFloats(list: ArrayList<Float>?): String {
return list?.joinToString(separator = ";") { it.toString() } ?: ""
}
@TypeConverter
fun toArrayListOfFloats(string: String?): ArrayList<Float> {
return ArrayList(string?.split(";")?.mapNotNull { it.toFloatOrNull() } ?: emptyList())
}
当我收敛ArrayList<SomeEntityObject>
时,它工作正常,但是在这种情况下,会出现上述错误。请帮忙!