Working with room database. I've made a class UserApp.kt to connect my Database to app. this class working good in activity.kt. But when I put the code inside Fragment.kt class, red line error showing under application text :
Unresolved reference: application
UserApp.kt
import android.app.Application
class UserApp: Application() {
val db by lazy {
UserDatabase.getInstance(this)
}
}
In activity the code like this:
val userDao = (application as UserApp).db.userDao()
getUsersFromRoom(userDao)
But in fragment the code like this: