title: Gettine Exception: java.lang.IllegalStateException: database not open
body: <p>Although it is a common error and there may be so many posts related to this exception. But here is the strange situation. I am getting the <code>java.lang.IllegalStateException: database not open</code> exception in Android 2.2. In remaining mobiles its working well.</p>
  
  <p>Logcat:</p>
  
  <pre><code>java.lang.IllegalStateException: database not open
  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1291)
  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1251)
  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1331)
  at com.mythrii.ilpa.DataHelper.checkRating(DataHelper.java:126)
  at com.mythrii.ilpa.SplashActivity$1.run(SplashActivity.java:35)
  at android.os.Handler.handleCallback(Handler.java:587)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:144)
  at android.app.ActivityThread.main(ActivityThread.java:4937)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>public class SplashActivity extends ActivityHelper
  {
  private DataHelper dh;
  // Set the display time, in milliseconds (or extract it out as a configurable parameter)
  private final int SPLASH_DISPLAY_LENGTH = 3000;
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.act__splash);
  
      dh = new DataHelper(this);
  
      dh.inserORupdateRating();
  }
  
  protected void onResume()
  {
      super.onResume();
  
          new Handler().postDelayed(new Runnable()
          {
              public void run()
              {
                  clearPref();
                  PrefBoolEdit("rating",dh.checkRating());//=&gt; Here is the exception
                  SplashActivity.this.finish();
                  Intent mainIntent = new Intent(SplashActivity.this, HomeActivity.class);
                  SplashActivity.this.startActivity(mainIntent);
              }
          }, SPLASH_DISPLAY_LENGTH);
  
  }
  
  protected void onDestroy() 
  {
      super.onDestroy();
      if (dh != null) 
      {
          dh.close();
      }
  }
  }
  </code></pre>
  
  <p>I am using this constructor to call in every activity</p>
  
  <p>Datahelper</p>
  
  <pre><code> public DataHelper(Context context) 
     {
  
        this.context  =   context;
        openHelper    =   new OpenHelper(this.context);
        this.db       =   openHelper.getWritableDatabase();
  
        Calendar c = Calendar.getInstance();    
        formattedDate = df.format(c.getTime());
     }
  </code></pre>
  
  <p>CheckRating</p>
  
  <pre><code>   public boolean checkRating()
     {
         Cursor cursor = this.db.query(TABLE_NAME_1, new String[] { "option" },
                 null, null, null, null, null);
  
         String option = null;
         //String date = null;
  
         boolean bool = false;
  
         if (cursor.moveToFirst())
            {
                do {
                    //date     = cursor.getString(0);
                    option = cursor.getString(0);
  
                 } while (cursor.moveToNext());
            }
            if (cursor != null &amp;&amp; !cursor.isClosed()) {
                cursor.close();
            }
  
            if(getRateCount()&gt;0)
            {
                if(!option.equals(ALREADY_RATED))
                {
                    bool = true;
                }
                else 
                {
                    bool = false;
                }
            }
            else 
            {
                  bool = false;
            }  
         return bool;
     }
  </code></pre>
  
  <p>Can anybody help me please..</p>