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
时,我遇到了这个错误,我想找出是哪个方法导致的。
我有多个 DAO
,总共大约有60个方法,在添加一个方法后出现了这个错误(复制并粘贴自另一个完美工作的方法,只更改了字段)。
我可以发布整个 DAO
类,但是我要求知道失败的方法。 我尝试过使用 Run with --stacktrace
、Run with --info
和 --debug option
,但这些都没有显示任何有价值的信息。
我添加的方法是一个具有 @Query
UPDATE
和 Int
返回类型的方法,如文档所建议。
UPDATE 或 DELETE 查询可以返回 void 或 int。 如果它是 int,则该值是此查询影响的行数。
编辑:我想补充说明,我尝试删除该方法,将 DAO 恢复到正常状态,但仍会出现此错误。
编辑2:添加 Gradle 控制台输出,因为在注释中无法阅读:
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
@Query("SELECT * FROM user") LiveData<List<User>> loadUsers();
当我将List
更改为Vector
时,例如:LiveData<Vector<User>> loadUsers();
我会得到以下错误信息:在 Android Studio 的 Gradle Console 窗口中显示了行位置UserDao.java:19
,并打印出了错误的方法,错误信息为error: Not sure how to convert a Cursor to this method's return type
。更多信息请参见 https://developer.android.com/studio/run/index.html#gradle-console。 - pskink