title: Room Database: how to get data one time?
body: <p>this my Database</p>
  <pre><code>@Database(entities = [UserModel::class], version = 1,exportSchema = false)
  abstract class UserRoomDatabase : RoomDatabase() {
      abstract fun getUserDao() : UserDAO
  
      companion object{
          @Volatile
          private var instance : UserRoomDatabase?= null
          fun getInstance(context : Context): UserRoomDatabase{
              if(instance==null)
                  instance = Room
                      .databaseBuilder(context,UserRoomDatabase::class.java,&quot;UserRoomDatabase&quot;)
                      .allowMainThreadQueries()
                      .build()
              return instance!!
          }
      }
  }
  </code></pre>
  <p>DAO interface</p>
  <pre><code>@Dao
  interface UserDAO {
      @Query(&quot;select * from user_table where _id =:id&quot;)
      fun readUserByIdSyncDAO(id : String) : UserModel
  }
  </code></pre>
  <p>Repository</p>
  <pre><code>class UserRepository(context : Context) {
      private val userDAO : UserDAO
      init {
          val userDatabase: UserRoomDatabase = UserRoomDatabase.getInstance(context)
          userDAO = userDatabase.getUserDao()
      }
  fun readUserByIdSyncDAO(id : String) : UserModel = userDAO.readUserByIdSyncDAO(id)
  }
  </code></pre>
  <p>ViewModel</p>
  <pre><code>class UserViewModel(private val userRepository: UserRepository) : ViewModel() {
         fun readUserByIdSyncDAO(id : String) : UserModel = userRepository.readUserByIdSyncDAO(id)
  }
  </code></pre>
  <p>and this is the way i use</p>
  <pre><code> val userModel = viewModel.readUserByIdSyncDAO(userId)
          Log.e(TAG,userModel.toString())
  </code></pre>
  <p>but i got the error</p>
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.ArrayList com.animals.snowy.models.UserModel.getFriends()' on a null object reference
  </code></pre>
  <p>why this error appear and how can i fix it?</p>
  <p>and i wonder if i use allowMainThreadQueries() in Database, is it better or worse for app?</p>