问题描述
尝试使用Kotlin在Android(测试运行器Robolectric)上使用真实数据库(而非模拟)测试存储库时,出现一个奇怪的错误。 在真实设备和模拟器上运行/调试应用程序都很好-没有任何错误。
因此比较失败,因为primaryKeyPostions不同。但是,为什么它们在测试中有所不同,而在真实设备/仿真器中却如此?
该实体看起来像这样:
════════ Exception caught by animation library ═════════════════════════════════
The following FormatException was thrown while notifying status listeners for AnimationController:
Trying to read MM from 20200814 at position 8
When the exception was thrown,this was the stack
#0 _DateFormatField.throwFormatException
package:intl/…/intl/date_format_field.dart:87
#1 _DateFormatPatternField.parseField
package:intl/…/intl/date_format_field.dart:337
#2 _DateFormatPatternField.parse
package:intl/…/intl/date_format_field.dart:250```
在SQLLite中,使用以下代码段创建了表:
@Entity(
tableName = "term",primaryKeys = ["id","language"],indices = [Index("id"),Index("language")]
)
data class Term(
@ColumnInfo(name = "id")
var termId: Int = 0,val language: String = "en",@ColumnInfo(name = "value")
var value: String = ""
)
更新:如果我将主键设置为非复合键,则所有位置都可以正常工作。但是我确实需要一个复合主键...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)