1

I have looked at other posts regarding the same, but i don't follow what mistake i must be doing. I have the same name declared in Entity for the class as well as in Database declaration file too. I'm also passing the same type of parameter as the entity class name, and still i'm getting this error thrown and it is not compiling. Here's my code. TIA

 @Entity(tableName = "current_task_table")
  data class CurrentTask (
    @PrimaryKey(autoGenerate = true) val uid: Int,
    @ColumnInfo(name = "task_name") val taskName: String
)

@Dao
interface CurrentTaskDao {

    @Query("SELECT * FROM current_task_table")
    fun getAllCurrentTask(): LiveData<List<CurrentTask>>

    @Insert
    suspend fun insertCurrentTask(currentTask: CurrentTask)

    @Query("DELETE FROM current_task_table")
    fun deleteAllCurrentTasks()
}

@Database(entities = [CurrentTask::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {

    abstract val currentTaskDao: CurrentTaskDao

    companion object {

        @Volatile
        private var instance: AppDatabase? = null

        fun getInstance(context: Context): AppDatabase? {
            if (instance == null) {
                synchronized(this) {
                    instance = Room.databaseBuilder(
                        context.applicationContext,
                        AppDatabase::class.java, "app_database"
                    )
                        .fallbackToDestructiveMigration()
                        .build()
                }
            }
            return instance
        }
    }
}
2
  • stackoverflow.com/questions/48015280/… Commented Jun 10, 2020 at 10:18
  • @IntelliJAmiya changing my interface to abstract class did not work either, could you explain why i should be doing that? Commented Jun 10, 2020 at 10:22

2 Answers 2

9

Fixed it by removing suspend from DAO

You cannot use suspend methods for DAO. Suspend function processed in compile time and compiler changes the signature of this function (different return type, an additional argument for state machine callback) to make it non-blocking. Room waits for particular method signature to generate code. So, until Room doesn't support coroutines directly, you cannot use suspend function for DAO.

Found my answer here: Error with Room dao class when using Kotlin coroutines

Sign up to request clarification or add additional context in comments.

1 Comment

Remove suspend from methods and its working
3

Removing the suspend is not necessary.
I solve this problem by this link.
Non-identification @Entity annotation

You need only have a small change in your build.gradle
please change this line

kapt "androidx.room:room-compiler:$room"

to this:

annotationProcessor  "androidx.room:room-compiler:$room"

You can use suspend form in your DAO by this way

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.