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
For me it was to change from MutableLiveData to LiveData as the return type of the get method.
In my case I was using androidx
dependencies for Room
and android.arch.
[old] dependencies for ViewModel
and LiveData
so I got this message
Solution:
Either use all androidx
dependencies OR use all old dependencies of andrio.arch
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List
to anything else inside the Dao
. I'd assume Room doesn't know how to deal with other return types. Take the List
and cast/convert it into your desired type outside of the Dao
.
For me it was because of mixing AndroidX with Pre-AndroidX. After a full migration and performing this, everything was back to normal. (Of course I moved to AndroidX-Room as well)
You have to include the @Relation annotation in the class returned by the method. It's the only way Room would know how to establish the relationship between the two.
class IdAndFullName {
public int uid;
@ColumnInfo(name = "full_name")
public String fullName;
}
// DAO
@Query("SELECT uid, name || lastName as full_name FROM user")
public IdAndFullName[] loadFullNames();
If there is a mismatch between the query result and the POJO, Room will give you this error message.
Or if you are using @SkipQueryVerification, you will also get this error.