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.
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.
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.
Got the same problem today, fixed by updating Room
version from 2.3.0
to 2.4.0-beta02
. Version can be found here: https://developer.android.com/jetpack/androidx/releases/room#2.3.0-alpha04
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With