这是我的实体类。我在这个类中使用了三个ENUM_INTEGER数据类型
@DatabaseTable
public class MessageData {
@DatabaseField(generatedId = true, columnName = ID_FIELD_NAME)
private Integer messageId;
@DatabaseField(dataType = DataType.DATE_TIME, columnName = DATE_FIELD_NAME)
private Date date;
@DatabaseField(dataType = DataType.ENUM_INTEGER, columnName = DIRECTION_FIELD_NAME)
private MessageEnums.MessageDirection direction;
@DatabaseField(columnName = CONTACT_ID_FIELD_NAME)
private String contactId;
@DatabaseField(columnName = MESSAGE_FIELD_NAME)
private String message;
@DatabaseField(dataType = DataType.ENUM_INTEGER, columnName = TYPE_FIELD_NAME)
private MessageEnums.MessageType type;
@DatabaseField(columnName = CONTENT_ADDRESS_FIELD_NAME)
private String contentAddress;
@DatabaseField(dataType = DataType.ENUM_INTEGER, columnName = STATUS_FIELD_NAME)
private MessageEnums.MessageStatus status;
@DatabaseField(columnName = READ_FIELD_NAME)
private boolean read;
//.....
}
这是我的枚举类
public class MessageEnums {
public enum MessageDirection{
IN,
OUT
}
public enum MessageType{
TEXT,
VOICE,
IMAGE,
STICKER,
AUDIO,
VIDEO,
LOCATION
}
public enum MessageStatus{
PENDING,
SENT,
DELIVERED,
RECEIVED
}
}
我使用此代码插入行
newMessageData = new MessageData(date, MessageEnums.MessageDirection.OUT, params[2], params[1]
, MessageEnums.MessageType.TEXT, "", MessageEnums.MessageStatus.SENT, true);
Dao<MessageData, Integer> dao = myApplication.getMessageDatabaseHelper().getMessageDao();
dao.create(newMessageData);
运行最后一行
后出现此错误无法在对象com.x.xx.database.MessageData@41a72790上运行insert stmt:INSERT INTO messagedata
(date
,direction
,contactID
,{{ 1}},message
,type
,contentAddress
,status
)VALUES(?,?,?,?,?,?,?,?)
答案 0 :(得分:1)
问题来自日期字段。当我将数据类型从DATE_TIME更改为DATE_STRING问题解决了。我不知道DATE_TIME的问题是什么。