Room“不确定如何将游标转换为此方法的返回类型":哪种方法? [英] Room "Not sure how to convert a Cursor to this method's return type": which method?

查看:438
本文介绍了Room“不确定如何将游标转换为此方法的返回类型":哪种方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.

使用Room我遇到此错误,我想找出导致该错误的方法.

Using Room I'm getting this error and I'd like to find out which method causes it.

我有多个DAO,总共有大约60个方法,并且在添加一个方法后才弹出此错误(从另一个运行良好的方法复制并粘贴,只需将字段设置为set即可).

I have multiple DAOs, with approximately 60 methods in total, and this error just popped up after adding a method (copy&pasted from another one that worked perfectly, just changed the field to set).

我可以发布整个DAO类,但是我正在寻求一种方法来知道哪种方法失败.我尝试使用Run with --stacktraceRun with --info--debug option,但是这些都没有显示任何有价值的信息.

I could post the whole class of DAOs, but I'm asking for a way to know which method failed. I tried with Run with --stacktrace, Run with --info and --debug option, but none of these show any valuable information.

我添加的方法是返回类型为Int@Query UPDATE,如

The method I added is a @Query UPDATE with Int return type, as suggested in the documentation

UPDATE或DELETE查询可以返回void或int.如果是整数,则 值是受此查询影响的行数.

UPDATE or DELETE queries can return void or int. If it is an int, the value is the number of rows affected by this query.

我想补充一点,我尝试删除该方法,使DAO返回工作状态,但它仍然给我这个错误.

I'd like to add that I tried deleting the method, bringing the DAO back to the working state, but it still gives me this error.

添加gradle控制台输出,因为注释中不可读:

Adding gradle console output because unreadable in comments:

error: Not sure how to convert a Cursor to this method's return type
error: Not sure how to convert a Cursor to this method's return type
2 errors

:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s

推荐答案

我整天都在这个问题上.解决方案非常简单.

I Spend the entire day on this issue. the solution was very simple. I was using something like this before

@Query("SELECT * FROM myTable")
fun getAll(): MutableLiveData<ArrayList<myData>>

现在,当我将ArrayList更改为 List 时,将MutableLiveData更改为 LiveData 即可.

Now when I changed ArrayList to List & MutableLiveData to LiveData it is working fine.

@Query("SELECT * FROM myTable")
fun getAll(): LiveData<List<myData>>

基于答案&关于此问题的评论,我认为会议室仅支持List& LiveData,因为我尝试使用MutableLiveData&也只有ArrayList.没有一种组合有效.

based on the answers & comments on this issue I think room support only List & LiveData because I tried with on MutableLiveData & only ArrayList too. none of the combinations worked.

希望这对某人有帮助.

Hope this will help someones few hours.

这篇关于Room“不确定如何将游标转换为此方法的返回类型":哪种方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆