androidkotlinandroid-roomandroid-architecture-componentsdata-access-object

DAO error:-Type of the parameter must be a class annotated with @Entity or a collection/array of it


I am new to android development and I am trying to make a notes app by following the android architecture components but on running I am getting errors in my DAO if any one could help would be highly grateful. Here's the code and the error that I am getting.

Error That I am getting

DAO:-

'''

@Dao
interface NoteDao {
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insert(note :Note)

    @Delete
    suspend fun delete(note : Note)

    @Query("SELECT * FROM Notes_table order by id")
    fun getALL(): LiveData<List<Note>>

    @Query("SELECT * From Notes_table where id= :pos")
    fun getSpecific(pos :Int):Note

}

'''

Entity:-

'''

@Entity(tableName = "Notes_table")
data class Note(@ColumnInfo(name="noteText") val text:String) {
    @PrimaryKey(autoGenerate = true) var id:Int =0

}

''' Database:-

'''

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

    abstract fun getNoteDao():NoteDao

    companion object{
        @Volatile
        private var Instance: NoteDatabase?=null

        fun getDatabase(context :Context):NoteDatabase{

            return Instance ?: synchronized(this){
                val instance=Room.databaseBuilder(context.applicationContext,
                NoteDatabase::class.java,"note_database").build()
                Instance=instance
                instance
            }
        }

    }

}

Imports For DAO:-

import androidx.lifecycle.LiveData
import androidx.room.

Imports for Entity:-

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

Imports for Database:-

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

I can provide the rest of the code if required.


Solution

  • With the help in the comment section and by reading the documentation I figured that something was wrong with my DAO and eventually it was something to do with the ROOM Version that I added to my dependencies I just updated those and now it's working fine.