title: Android SQLite Database No such table issue
body: <p>I am using SQLite Database in my application for normal insertion and fetching purpose. I am facing <strong>No such table issue</strong> while trying to get table row count for the particular table.</p>
  
  <p><strong>Logcat Error:</strong></p>
  
  <pre><code>Fatal Exception: android.database.sqlite.SQLiteException: no such table: table_name(code 1): , while compiling: SELECT * FROM table_name
         at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
         at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
         at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
         at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
         at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
         at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37)
         at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
         at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
         at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
         at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
         at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)
         at com.takeoffandroid.database.DBAccess.getCount(SourceFile:384)
         at   com.takeoffandroid.database.DBAccess.isTableCountLogic(SourceFile:402)
         at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
         at android.os.Handler.dispatchMessage(Handler.java:102)
         at android.os.Looper.loop(Looper.java:148)
         at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p><strong>SQLite create Table query:</strong></p>
  
  <pre><code>private static final String TEXT_TYPE = " TEXT";
  private static final String COMMA_SEP = ",";
  private static final String INTEGER_PRIMARY_KEY = " INTEGER PRIMARY KEY AUTOINCREMENT";
  
  
  public static final String TABLE_NAME = "table_name";
  
  private static final String COLUMN_ID = "ID";
  
  private static final String COLUMN_URL = "url";
  private static final String COLUMN_JSON = "json";
  
  private static final String CREATE_TABLE_QUERY = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
              COLUMN_ID + INTEGER_PRIMARY_KEY + COMMA_SEP +
              COLUMN_URL + TEXT_TYPE + COMMA_SEP +
              COLUMN_JSON + TEXT_TYPE + ")";
  
  
  
  public static DBAccess init(Context context) {
  
  
          if (mInstance == null)
              synchronized (DBAccess.class) {
                  if (mInstance == null) {
                      mInstance = new DBAccess(context);
  
                  }
              }
          return mInstance;
      }
  
      public DBAccess(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
              db.execSQL(CREATE_TABLE_QUERY);
      }
  </code></pre>
  
  <p><strong>Method to get table row count:</strong></p>
  
  <pre><code> public  int getCount() {
  
  
          int count=0;
          SQLiteDatabase db=getReadableDatabase();
          Cursor cursor=db.query(TABLE_NAME, null, null, null, null, null, null);
  
          count = cursor.getCount();
  
          CLog.i("Table count", "Table count size is "+String.valueOf(count));
  
          cursor.close();
          db.close();
          close();
  
          return count;
  
      }
  </code></pre>
  
  <p>Please help me if there is any issue in my code, I am completely stucK up with this issue since long time and I couldn't find the solution. Any kinda suggestions would be helpful to me. </p>
  
  <p><strong>Note:</strong> This is a very random issue which is happening only with few devices.</p>