Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Not sure how to convert a Cursor to this method's return type after Kotlin update to 1.6.0

I was using Android Room library in my project to manipulate data from my SQLite database and everything was working fine in previous Kotlin version (1.5.31). Here is a sample of my DAO:

@Dao
interface ServersDao {

    @Query("SELECT * FROM servers ORDER BY connectedDevices, ping ASC LIMIT 1")
    suspend fun getLeastLoadedServer(): Server

    @Query("SELECT * FROM servers ORDER BY ping, connectedDevices ASC LIMIT 1")
    suspend fun getNearestServer(): Server
}

After updating Kotlin to version 1.6.0, my code couldn't compile anymore, and I am receiving this error:

error: Not sure how to convert a Cursor to this method's return type (java.lang.Object). public abstract java.lang.Object getLeastLoadedServer(@org.jetbrains.annotations.NotNull()

After some searching, I read that it was because of suspending functions, so I removed suspend keyword from my DAO, and I started getting the obvious error:

java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.

Even if I was calling those function from a IO coroutine.

I also read through the change log of Kotlin 1.6.0, that did not help much.

Any help is appreciated, thanks.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Using Android Room 2.4.0 will solve the issue.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!