Issue
I need to get a string from my room database and set it as text in a textview i'm using this code in my dao
@Query("SELECT question, question_heat, question_gender FROM questions WHERE question_heat = :heat AND question_gender = :gender" +
" ORDER BY RANDOM() LIMIT 1")
String getQuestion(int heat, int gender);
i just want to get a random question from my question database.I get this error:
error: Not sure how to convert a Cursor to this method's return type String getQuestion(int heat, int gender);
in the build output says the error is in the query
i'm really new in room i was using sqlopenhelper for a while and i don't really know what to do here.
i found some codes in google but they were for lists of data and i want to get just a string.
Solution
You must select only question
column. Try this way:
@Query("SELECT question FROM questions WHERE question_heat = :heat AND question_gender = :gender ORDER BY RANDOM() LIMIT 1")
String getQuestion(int heat, int gender);
Answered By - Garnik
Answer Checked By - Katrina (JavaFixing Volunteer)