Skip to content
Advertisement

Room: error: Not sure how to convert a Cursor to this method’s return type (void)

I have this query set up to return all the records from these tables and display the information on a recyclerview in android. the DB is set up using the Room persistence library aka SQLITE.

When I try to compile the app I get the following error:

The query returns some columns which are not used by com.example.feelingfit.persistence.tables.MoodBeforeTable. You can use @ColumnInfo annotation on the fields to specify the mapping.

Could anyone help me debug this and find out why the app wont compile?

Advertisement

Answer

Problem is Room cannot map the result from your custom query to existing MoodBeforeTable. It is because your return type is List<MoodBeforeTable> but you have used joins using TwistedThinkingTable and MoodAfterTable and so on.

What you should do is create a new POJO like below:

Then use this class as the return type like :

LiveData<List<MoodLogPojo>> moodLogsAll (int userId, String date);.

NOTE: Mind the MoodLogPojo class. Modify it accoring to the corresponding data types from each Entity.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement