OrmLite java.lang.IllegalStateException: you must call initialize() before you can use the dao
<p>I am using ORMLite to persist my object in my <code>SqliteDatabase</code> in my app.</p>

<p>I am getting this exception while trying to get a DAO in order to persist an object. </p>

<p>The documentation says I have to call the <code>initialize()</code> method before I can use the DAO, and the OrmLite documentation (insufficient) says:</p>

<blockquote>
  <p><strong>BaseDaoImpl (class)</strong><br>
  initialize(): Initialize the various DAO configurations after the various setters have been called.</p>
</blockquote>

<p>The problem is, I get the DAOs by calling <code>getDao(class)</code>, and there is no <code>initialize()</code> that I can call neither on DAOs nor in my class that extends <code>OrmLiteSqliteOpenHelper</code>.</p>

<p>This is my custom <code>OpenHelper</code> class code:</p>

<pre><code>public class LocalDBHelper extends OrmLiteSqliteOpenHelper {
  private LocalDBHelper(Context context){
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  public static LocalDBHelper getInstance(Context context) {
    if (instance == null) instance = new LocalDBHelper(context);
    return instance;
  }

  @Override
  public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, Barrio.class);
        TableUtils.createTable(connectionSource, Fenomeno.class);
        TableUtils.createTable(connectionSource, Info.class);
        TableUtils.createTable(connectionSource, TelefonoUtil.class);
        TableUtils.createTable(connectionSource, Alarma.class);
        TableUtils.createTable(connectionSource, ReplicaAlerta.class);
    } catch (SQLException e) {
        e.printStackTrace();
        Log.d(TAG, e.getMessage());
    }
  }

  @Override
  public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        TableUtils.dropTable(connectionSource, Barrio.class, true);
        TableUtils.dropTable(connectionSource, Fenomeno.class, true);
        TableUtils.dropTable(connectionSource, Info.class, true);
        TableUtils.dropTable(connectionSource, TelefonoUtil.class, true);
        TableUtils.dropTable(connectionSource, Alarma.class, true);
        TableUtils.dropTable(connectionSource, ReplicaAlerta.class, true);
    } catch (SQLException e) {
        e.printStackTrace();
        Log.d(TAG, e.getMessage());
    }
  }
</code></pre>

<p>And this is the full stack of Android Monitor:</p>

<pre><code>java.lang.IllegalStateException: you must call initialize() before you can use the dao
        at com.j256.ormlite.dao.BaseDaoImpl.checkForInitialized(BaseDaoImpl.java:1061)
        at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:316)
        at com.org.siam.app.controller.BarrioController.actualizarTodos(BarrioController.java:75)
        at com.org.siam.app.remote.BarriosWebService.onResponse(BarriosWebService.java:43)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
</code></pre>

<p>EDIT: added an <code>Application</code> subclass called <code>SiacApplication</code>, <code>onCreate()</code> method code here (also registered on manifest):</p>

<pre><code>@Override
public void onCreate() {
    super.onCreate();
    LocalDBHelper.getInstance(this);
}
</code></pre>

<p>EDIT 2: added DAO getter (the DAO is a local field):</p>

<pre><code>    public Dao&lt;Barrio, Long&gt; getBarrioDao() throws SQLException {
    if (barrioDao == null) barrioDao = getDao(Barrio.class);
    return barrioDao;
}
</code></pre>