title: Error inputing data into the database using Room, Dao
body: <p>This is my first time using Room and LiveData. I keep getting errors about inputing data into the database using Dao(Database access object). I have tried updating build.gradle files, but it doesn't solve the errors. It says "getDatabase called recursively".</p>
  
  <p>My logcat below:</p>
  
  <pre><code> 2019-08-01 13:35:55.644 18117-18149/com.example.inventory E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_0
      Process: com.example.inventory, PID: 18117
      java.lang.RuntimeException: Exception while computing database live data.
          at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:92)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
          at java.lang.Thread.run(Thread.java:764)
       Caused by: java.lang.IllegalStateException: getDatabase called recursively
          at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:338)
          at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
          at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
          at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
          at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:452)
          at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:275)
          at com.example.inventory.data.InventoryDao_Impl.insert(InventoryDao_Impl.java:58)
          at com.example.inventory.data.InventoryRoomDatabase$PopulateDbAsync.&lt;init&gt;(InventoryRoomDatabase.java:46)
          at com.example.inventory.data.InventoryRoomDatabase$1.onOpen(InventoryRoomDatabase.java:34)
          at com.example.inventory.data.InventoryRoomDatabase_Impl$1.onOpen(InventoryRoomDatabase_Impl.java:58)
          at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:120)
  </code></pre>
  
  <p>Room database class</p>
  
  <pre><code>@Database(entities = Product.class, version = 1, exportSchema = false)
  public abstract class InventoryRoomDatabase extends RoomDatabase {
  
      public abstract InventoryDao inventoryDao();
  
      public static InventoryRoomDatabase INSTANCE;
  
      public static InventoryRoomDatabase getDatabase(final Context context) {
          synchronized (InventoryRoomDatabase.class) {
              if (INSTANCE == null) {
                  INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                          InventoryRoomDatabase.class, "inventory_table")
                          .fallbackToDestructiveMigration().addCallback(roomDatabaseCallback).build();
              }
          }
          return INSTANCE;
      }
  
      private static RoomDatabase.Callback roomDatabaseCallback = new RoomDatabase.Callback() {
          @Override
          public void onOpen(@NonNull SupportSQLiteDatabase db) {
              super.onOpen(db);
              new PopulateDbAsync(INSTANCE).execute();
  
          }
      };
  
      private static class PopulateDbAsync extends AsyncTask&lt;Void, Void, Void&gt; {
  
          private final InventoryDao mDao;
          Product product = new Product("Ice cream", 0.99, 70);
  
          PopulateDbAsync(InventoryRoomDatabase db) {
              mDao = db.inventoryDao();
              mDao.insert(product);
          }
  
          @Override
          protected Void doInBackground(Void... voids) {
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Dao interface</p>
  
  <pre><code>@Dao
  public interface InventoryDao {
  
      @Insert
      void insert(Product product);
  
      @Query("DELETE FROM inventory_table")
      void deleteAll();
  
      @Query("SELECT * from inventory_table")
      LiveData&lt;List&lt;Product&gt;&gt; getAllProducts();
  }
  </code></pre>