title: Show ProgressDialog in SQLiteOpenHelper onCreate method
body: <p>I'm new in android programming. I'm writing simple application that should execute sql file, in first run. But it seems that this process take couple of seconds so I figure that application should show progressDialog while it will be executing sql file. But when I try to run application, dialog is showing with message "app has stopped ...". Please help me.</p>
  
  <pre><code>@Override
  public void onCreate(SQLiteDatabase database)
  {
      String CREATE_BIBLE_TABLE = "CREATE TABLE bible (" +
              "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
              "book INTEGER, " +
              "chapter INTEGER NOT NULL, " +
              "verse INTEGER NOT NULL, " +
              "content TEXT" +
              ")";
      database.execSQL(CREATE_BIBLE_TABLE);
  
      new FirstLoadAsyncTask(database).execute();
  }
  
  public class FirstLoadAsyncTask extends AsyncTask&lt;Void, Void, Void&gt;
  {
      private SQLiteDatabase database;
      private ProgressDialog progressDialog;
  
      public FirstLoadAsyncTask(SQLiteDatabase database)
      {
          this.database = database;
      }
  
      @Override
      protected void onPreExecute()
      {
          ((Activity) context).runOnUiThread(new Runnable()
          {
              @Override
              public void run()
              {
                  progressDialog = ProgressDialog.show(context, "Loading...", "");
              }
          });
      }
  
      @Override
      protected Void doInBackground(Void... params)
      {
          try
          {
              InputStream inputStream = context.getAssets().open("bible.sql");
              execSqlFile(database, inputStream);
          } catch(IOException e)
          {
              e.printStackTrace();
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result)
      {
          progressDialog.dismiss();
      }
  } 
  </code></pre>
  
  <p>Class extends SQLiteOpenHelper.</p>
  
  <p>Edit:
  Logcat:</p>
  
  <pre><code>01-06 18:27:53.221  14118-14118/pl.several27.Biblia_Warszawska E/Trace﹕ error opening trace file: No such file or directory (2)
  01-06 18:27:53.891  14118-14118/pl.several27.Biblia_Warszawska I/Adreno200-EGL﹕ &lt;qeglDrvAPI_eglInitialize:299&gt;: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.081_msm7627a_JB_REL_2.0.3_CL2820657_release_AU (CL2820657)
      Build Date: 01/22/13 Tue
      Local Branch:
      Remote Branch: quic/jb_rel_2.0.3
      Local Patches: NONE
      Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.081 +  NOTHING
  01-06 18:27:54.001  14118-14118/pl.several27.Biblia_Warszawska E/copybit﹕ Error opening frame buffer errno=13 (Permission denied)
  01-06 18:27:54.001  14118-14118/pl.several27.Biblia_Warszawska W/Adreno200-EGLSUB﹕ &lt;updater_create_surface_state:342&gt;: updater_create_surface_state failed to open copybit, error: -13
  01-06 18:27:54.011  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x53be8000 size:1536000 offset:0 fd:61
  01-06 18:27:54.021  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x5083a000 size:4096 offset:0 fd:63
  01-06 18:27:54.381  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x541fb000 size:1536000 offset:0 fd:66
  01-06 18:27:54.381  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x50a50000 size:4096 offset:0 fd:68
  01-06 18:27:54.501  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x54472000 size:1536000 offset:0 fd:70
  01-06 18:27:54.501  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x50c75000 size:4096 offset:0 fd:72
  01-06 18:27:55.001  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x545e9000 size:1536000 offset:0 fd:74
  01-06 18:27:55.001  14118-14118/pl.several27.Biblia_Warszawska D/memalloc﹕ ion: Mapped buffer base:0x50d4c000 size:4096 offset:0 fd:76
  01-06 18:27:57.231  14118-14118/pl.several27.Biblia_Warszawska D/book choosen﹕ 1
  01-06 18:27:57.581  14118-14118/pl.several27.Biblia_Warszawska W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40ca4540)
  01-06 18:27:57.601  14118-14118/pl.several27.Biblia_Warszawska E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.several27.Biblia_Warszawska/pl.several27.Biblia_Warszawska.ChapterActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
              at android.app.ActivityThread.access$600(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:155)
              at android.app.ActivityThread.main(ActivityThread.java:5520)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
              at pl.several27.Biblia_Warszawska.Database$FirstLoadAsyncTask.onPreExecute(Database.java:58)
              at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
              at android.os.AsyncTask.execute(AsyncTask.java:534)
              at pl.several27.Biblia_Warszawska.Database.onCreate(Database.java:42)
              at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
              at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
              at pl.several27.Biblia_Warszawska.Database.countChapters(Database.java:148)
              at pl.several27.Biblia_Warszawska.ChapterActivity.onCreate(ChapterActivity.java:32)
              at android.app.Activity.performCreate(Activity.java:5066)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
              at android.app.ActivityThread.access$600(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:155)
              at android.app.ActivityThread.main(ActivityThread.java:5520)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
              at dalvik.system.NativeStart.main(Native Method)
  01-06 18:27:59.511  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ killProcess, pid=14118
  01-06 18:27:59.521  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ dalvik.system.VMStack.getThreadStackTrace(Native Method)
  01-06 18:27:59.521  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ java.lang.Thread.getStackTrace(Thread.java:599)
  01-06 18:27:59.521  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ android.os.Process.killProcess(Process.java:956)
  01-06 18:27:59.521  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:108)
  01-06 18:27:59.531  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
  01-06 18:27:59.531  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
  01-06 18:27:59.531  14118-14118/pl.several27.Biblia_Warszawska D/Process﹕ dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Also I tried this way <a href="https://stackoverflow.com/questions/7201741/display-progressdialog-in-non-activity-class?answertab=votes#tab-top">display progressdialog in non-activity class</a> but it won't work too.</p>
  
  <p>And here is whole application source code but without dialog: <a href="https://github.com/several27/BibliaWarszawska_Android" rel="nofollow noreferrer">https://github.com/several27/BibliaWarszawska_Android</a></p>
  
  <p>Please can anyone help me?</p>