title: Error: Cannot access database on the main thread since it may potentially lock the UI for a long period of time. - Android Room using Kotlin
body: <p>Okay, so, I am trying to use Android Room to create this database for this project.</p>
  
  <p>First of all, this is what I have in my Gradle file regarding the issue:</p>
  
  <pre><code>//Room database
      implementation "androidx.lifecycle:lifecycle-viewmodel:2.1.0"
  
      implementation "androidx.room:room-runtime:2.2.3"
      kapt "androidx.room:room-compiler:2.2.3"
      implementation "androidx.room:room-ktx:2.2.3"
  </code></pre>
  
  <p>Here's the Dao Code:</p>
  
  <pre><code>@Dao
  interface DebtsDao {
  
      @Query("SELECT * FROM debts")
      fun getDebtsList() : List&lt;Debts&gt;
  
      @Query("SELECT * FROM debts WHERE name LIKE :name")
      fun getNamedDebt(name : String) : Debts
  
      @Insert
      fun insertInDatabase(debt : Debts)
  
      @Delete
      fun deleteFromDatabase(debt : Debts)
  
  }
  </code></pre>
  
  <p>The database bit: </p>
  
  <pre><code>@Database(entities = arrayOf(Debts::class), version = 1)
  abstract class AppDatabase : RoomDatabase()
  {
      abstract fun debtsDao() : DebtsDao
  }
  
  </code></pre>
  
  <p>And this is the function where I use it: </p>
  
  <pre><code>    fun refreshRecyclerView()
      {
          val database = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "account").build()
  
          val list : List&lt;Debts&gt; = database.debtsDao().getDebtsList()
  
          recycler_view_debts.layoutManager = LinearLayoutManager(this)
          recycler_view_debts.adapter = RecAdapter(this, list)
      }
  </code></pre>
  
  <p>I tried following the tutorial on Android's page, but it didn't work as expected. I got the following error on Android Studio:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.project.watchingmoneyfly, PID: 17067
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.watchingmoneyfly/com.project.watchingmoneyfly.Activities.MainActivity}: java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
          at android.app.ActivityThread.-wrap12(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6077)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
       Caused by: java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
          at androidx.room.RoomDatabase.assertNotMainThread(RoomDatabase.java:267)
          at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:351)
          at com.project.watchingmoneyfly.RoomDatabase.DebtsDao_Impl.insertInDatabase(DebtsDao_Impl.java:79)
          at com.project.watchingmoneyfly.Activities.MainActivity.onCreate(MainActivity.kt:25)
          at android.app.Activity.performCreate(Activity.java:6662)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
          at android.app.ActivityThread.-wrap12(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:154) 
          at android.app.ActivityThread.main(ActivityThread.java:6077) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
  </code></pre>
  
  <p>This should be the head of the problem: Cannot access the database on the main thread since it may potentially lock the UI for a long period of time.</p>
  
  <p>What am I missing here? Thanks in advance!!</p>