方法是哪个?“不确定如何将游标转换为此方法的返回类型”的房间:

116
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 --stacktraceRun with --info--debug option,但这些都没有显示任何有价值的信息。

我添加的方法是一个具有 @Query UPDATEInt 返回类型的方法,如文档所建议。

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

1
Gradle控制台中的完整错误消息是什么? - pskink
@pskink将完整的错误信息添加到了问题中。 - David Corsalini
1
这是我的方法,它可以编译通过:@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
1
我正在使用 Kotlin 进行构建,也许这就是为什么我不理解这一行的原因? - David Corsalini
5
今天我遇到了相同的问题(返回类型是rxjava2 Observable)。错误消息中没有任何关于问题所在的信息。我希望Google能够使错误消息更加详细。至少应该打印出方法名称或期望的返回类型... - ntoskrnl
显示剩余6条评论
32个回答

-1

我将 Kotlin 版本从 1.5.21 回退到 1.3.61 后,此错误消失了。


1
这并没有提供解决问题的方法。需要确定问题的原因。降级 Kotlin 版本从来都不是一个解决方案。 - Fuad Kamal

-1
对我来说,重要的是将get方法的返回类型从MutableLiveData更改为LiveData。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接