title: Adding initial data in Realm Android
body: <p>I'm using realm and all looks good until I try to add initial data in my database.</p>
  
  <p>I followed the example in this <a href="https://stackoverflow.com/questions/33674982/realm-with-pre-populated-data-into-assets#answer-37326580"><strong>answer</strong></a>, so in my class, that inherits from <code>Application</code>, I have the following:</p>
  
  <pre><code>public class MainApplication extends Application {
      @Override
      public void onCreate() {
          super.onCreate();
          Realm.init(this);
          final Map&lt;String, String&gt; map = new LinkedHashMap();
          map.put("Key1", "value1");
          map.put("Key2", "value2");
          RealmConfiguration config = new RealmConfiguration.Builder().initialData(new Realm.Transaction() {
              @Override
              public void execute(Realm realm) {
                  int i = 1;
                  for (Map.Entry entry : map.entrySet()) {
                      realm.beginTransaction();
                      Category c = realm.createObject(Category.class, i++);
                      c.setName((String) entry.getKey());
                      c.setDescription("Category #" + entry.getValue());
                      realm.commitTransaction();
                  }
                  realm.close();
              }
          }).deleteRealmIfMigrationNeeded().name("realm.db").build();
          Realm.setDefaultConfiguration(config);
      }
  }
  </code></pre>
  
  <p>And I thought this configuration should work, however I'm getting the following error:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: The Realm is already in a write transaction in /path/...</p>
  </blockquote>
  
  <p>Is there something that I'm missing?</p>
  
  <p>Thanks in advance.</p>