Question: I'm trying to call my database (made with Room) from an activity on Android, but it needs the application context, and if I passed "application : Application" in the constructor of my Activity, the build crash and tell me :

> 
> java.lang.Class<com.exemple.instabus.PhotoActivity> has no zero argument constructor
> 
> 
> 

Here is my code :

```
class PhotoActivity(application: Application) : AppCompatActivity() {

    private val pictureDao = PictureDatabase.getDatabase(app)

//Some code ....

```

I need a context, i've tried to pass "this" but i got another error

Can someone give me some help please, I'm a beginner in this technology

EDIT:

Here is my database class, just to show you why I need an Application Context

```

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

    abstract fun pictureDao() : PictureDao

     companion object{
        @Volatile
        private var INSTANCE : PictureDatabase? = null

        fun getDatabase(context: Context): PictureDatabase {
            if(INSTANCE == null){
                synchronized(this){
                    INSTANCE = Room.databaseBuilder(
                            context.applicationContext,
                            PictureDatabase::class.java,
                            "pictures.db"
                    ).build()
                }
            }
            return INSTANCE!!
        }
    }

}

```

Answer: 
First create a ViewModel, and inside the ViewModel you can access the your Dao, pictureDao.

```
 class PictureViewModel(application: Application) : 
   AndroidViewModel(application) {

     val pictureDao: PictureDao

     init {
         pictureDao = 
        PictureDatabase.getDatabase(application).pictureDao()

         }

      }

```

Then in your activity, initialize the ViewModel. And access your Dao.

```
 class PhotoActivity : AppCompatActivity() {

   private lateinit var pictureViewModel: PictureViewModel

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_photo)

    pictureViewModel = 
   ViewModelProviders.of(this).get(PictureViewModel::class.java)

   //You can now access your Dao class here:
   val pictureDao = pictureViewModel.pictureDao

 }
 }

```
You should not pass `Application` to the constructor. You should pass `applicationContext` to `getDatabase()`, like `private val pictureDao = PictureDatabase.getDatabase(applicationContext)`