【发布时间】:2018-03-08 19:53:44
【问题描述】:
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 我遇到了这个错误,我想知道是什么方法导致的。
我有多个DAOs,总共大约有 60 个方法,并且在添加一个方法后才弹出此错误(从另一个完美运行的方法复制并粘贴,只是将字段更改为设置)。
我可以发布DAOs 的整个课程,但是我要求一种方法来知道哪个方法失败了。我尝试了Run with --stacktrace、Run with --info 和--debug option,但这些都没有显示任何有价值的信息。
我添加的方法是@QueryUPDATE,返回类型为Int,正如documentation中所建议的那样
UPDATE 或 DELETE 查询可以返回 void 或 int。如果是 int,则 value 是受此查询影响的行数。
编辑:我想补充一点,我尝试删除该方法,使 DAO 恢复工作状态,但它仍然给我这个错误。
EDIT2:添加 gradle 控制台输出,因为在 cmets 中不可读:
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
【问题讨论】:
-
gradle 控制台的完整错误信息是什么?
-
@pskink 将完整的错误消息添加到问题中
-
这是我编译得很好的方法:
@Query("SELECT * FROM user") LiveData<List<User>> loadUsers();当我将List更改为Vector例如我得到:UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers();在 Gradle 控制台 android studio的窗口-注意它显示UserDao.java:19这是一个行位置,它还打印错误的方法,更多developer.android.com/studio/run/index.html#gradle-console -
我是从 Kotlin 构建的,也许这就是为什么我没有接听电话?
-
我今天遇到了同样的问题(返回类型是 rxjava2 Observable)。错误消息不包含有关问题所在位置的任何信息。我希望谷歌将使错误消息更具信息性。至少它应该打印一个方法名称或预期的返回类型......
标签: android dao android-room kapt android-architecture-components