title: "No such table" error when inserting into a new table
body: <p>I am trying to create a database but when I attempt to insert values into the table I get an error saying that no table is found.</p>
  
  <p>This is my databasemanager class:</p>
  
  <pre><code>public class DatabaseManager {
      private Context context = null;
      private SQLiteDatabase database=null;
      private DatabaseHelper dbHelper=null;
  
      public DatabaseManager(Context context) {
          this.context = context;
          dbHelper = new DatabaseHelper(context);
      }
  
      public void open() throws SQLException {
          if (dbHelper==null) {
              dbHelper = new DatabaseHelper(context);
          }
  
          if (database==null) {
              database = dbHelper.getWritableDatabase();
          }
      }
  
      public void close() {
          dbHelper.close();
          database = null;
          dbHelper = null;       
      }
  
      public long insertCategoriesDetail(Category categorydetail){
          long result = 0;
  
          try{
              if (database==null) {
                  open();
              }
              ContentValues values = new ContentValues();
              values.put(DatabaseContract.RetailDatabaseEntry.COLUMN_CATEGORYDESCRIPTION, categorydetail.getCategorydescription());
              //values.put(DatabaseContract.RetailDatabaseEntry.COLUMN_CATEGORYIMAGE, categorydetail.getCategoryimage());
  
              result = database.insert(DatabaseContract.RetailDatabaseEntry.TABLE_NAME_CATEGORY, null, values);
              Toast.makeText(context, "Res : " + result, Toast.LENGTH_SHORT).show();
              close();
          }
          catch(Exception ex){
              Toast.makeText(context, "crashed" + ex.toString(), Toast.LENGTH_SHORT).show();
          }
  
          return result;
      }
  
      public List&lt;Category&gt; getCategoriesDetail() {
          if (database==null) {
              open();
          }
  
          List&lt;Category&gt; categoriesdetailsList = new ArrayList&lt;Category&gt;();
  
          // Select All Query
          String selectQuery = "SELECT  * FROM " + DatabaseContract.RetailDatabaseEntry.TABLE_NAME_CATEGORY;
  
          Cursor cursor = database.rawQuery(selectQuery, null);
  
          // looping through all rows and adding to list
          if (cursor.moveToFirst()) {
              do {
                  Category detailList = new Category();
                  detailList.setId(Integer.parseInt(cursor.getString(0)));
                  detailList.setCategorydescription(cursor.getString(1));
                  detailList.setCategoryimage(cursor.getBlob(2));
                  categoriesdetailsList.add(detailList);
              } while (cursor.moveToNext());
          }
  
          close();
          return categoriesdetailsList;
      }
  }
  </code></pre>
  
  <p>This is db creation class:</p>
  
  <pre><code>public class DatabaseHelper extends SQLiteOpenHelper {
      private static final String TEXT_TYPE = " TEXT";
      private static final String INTEGER_TYPE = " INTEGER";
      private static final String COMMA_SEP = ", ";
      private static final String BLOB_TYPE = " BLOB";
  
      private static final  String SQL_CREATE_RETAIL_DB_CATEGORY =
      "CREATE TABLE " + DatabaseContract.RetailDatabaseEntry.TABLE_NAME_CATEGORY + " (" +
      DatabaseContract.RetailDatabaseEntry.COLUMN_ID_CATEGORY+ " INTEGER PRIMARY KEY AUTOINCREMENT," +
      DatabaseContract.RetailDatabaseEntry.COLUMN_CATEGORYDESCRIPTION + TEXT_TYPE + COMMA_SEP +
      DatabaseContract.RetailDatabaseEntry.COLUMN_CATEGORYIMAGE + BLOB_TYPE + " )";
  
      private static final String SQL_DELETE_RETAIL_DB_CATEGORY =
      "DROP TABLE IF EXISTS " + DatabaseContract.RetailDatabaseEntry.TABLE_NAME_CATEGORY ;
  
      public static final int DATABASE_VERSION = 1;
      public static final String DATABASE_NAME = "RETAILNYURALS.db";
  
      public DatabaseHelper(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @SuppressLint("NewApi")
      public DatabaseHelper(Context context, String name, CursorFactory factory,
  
      int version, DatabaseErrorHandler errorHandler) {
          super(context, name, factory, version, errorHandler);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          db.execSQL(SQL_CREATE_RETAIL_DB_CATEGORY);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL(SQL_DELETE_RETAIL_DB_CATEGORY);
          onCreate(db);
      }
  }
  </code></pre>