android - 通过房间库选择多桩柱
问题描述
我想在 Android SDK 环境中通过 Room Library 从 SqlLite 中选择多个列。下面是选择它的查询。@Query("SELECT ID,message,timestamp FROM Chat_Message WHERE groupID =:groupID ORDER BY timestamp DESC LIMIT 1") public List get_last_msg_ID_timestamp (String groupID); 我在主类下定义的 Last_Msg_Detail 类如下:- public class Last_Msg_Detail { public Integer ID; 公共字符串消息;公共长时间戳;}
For accessing this three variable have created below method :-
Last_Msg_Detail last_record_t = new Last_Msg_Detail();
public Last_Msg_Detail get_last_msgand_time_stamp(String groupID){
List<Last_Msg_Detail> last_record =
chat_messageDao.get_last_msg_ID_timestamp(groupID);
last_record_t = last_record.get(0);
return last_record_t;
}
On Rebuilding Project, getting follow error
1. error: Cannot figure out how to save this field into database. You can
consider adding a type converter for it.
2. error: Not sure how to convert a Cursor to this method's return type
Kindly advise how to resolve.
在此先感谢您的帮助。
解决方案
您的方法返回自定义对象,并且该对象有很多字段。
因此,当您尝试返回特定列时,您会尝试返回一个新对象。所以发生错误。
要解决此问题,请为选定的列创建一个新对象。它必须有这些字段。
ID,message,timestamp
并在您的方法中使用该对象
@Query("SELECT ID,message,timestamp FROM Chat_Message WHERE groupID =:groupID ORDER BY timestamp DESC LIMIT 1")
public List<NEW_OBJECT> get_last_msg_ID_timestamp (String groupID);
推荐阅读
- bash - 无法在 shell 脚本中设置条件
- c++ - 为什么来自匿名对象的 std::pair 会复制该对象而不是移动?
- r - 错误消息“配对中的错误 || !is.null(y) : 'x || y' 中的 'x' 类型无效”
- python - 'pip install pybullet' 导致错误“无法打开输入文件 'Ws2_32.lib'”
- html - Laravel 如何更改“这些凭据与我们的记录不匹配”
- python - Appending sections of a file into duplicates of a previously written file
- postgresql - Aqueduct failed to execute db migration file
- python - KivyMD 如何使用 on_focus 事件获取焦点文本字段的 id
- ruby-on-rails - Solidus: [Spree WARNING] Missing migrations
- python - Django单元测试“匹配查询不存在”