title: Android SQLite "no such table" exception
body: <p>I'm starting into SQLite and databases in Android and I just found this issue. I have read a lot of similar questions but I have not found a solution yet.</p>
  
  <p>This is the error I'm getting:</p>
  
  <blockquote>
    <p>E/AndroidRuntime(529): Caused by: android.database.sqlite.SQLiteException: no such table: ligas_bd: , while compiling:  SELECT * FROM ligas_bd</p>
  </blockquote>
  
  <p>This is my code. </p>
  
  <pre><code>DBHelper myDbHelper = new DBHelper(this);
  myDbHelper = new DBHelper(this);
  try {
      myDbHelper.createDataBase();
  } catch (IOException ioe) {
      throw new Error("Unable to create database");
  }
  try {
      myDbHelper.open();
      SQLiteDatabase db = null;
      db = myDbHelper.getWritableDatabase();
      String[] args = new String[] {""};
      Cursor c = db.rawQuery(" SELECT * FROM ligas_bd", args); &lt;---- Error in this line
      if (c.moveToFirst()) {
          do {
              String cod = c.getString(0);
              String nombre = c.getString(1);
              String flag = c.getString(0);
              String cod_url = c.getString(0);
              ligas.add(new Item_Liga(nombre, flag, cod, cod_url));
          } while(c.moveToNext());
      }
  }catch(SQLException sqle){
      throw sqle;
  }
  </code></pre>
  
  <p>DBHelper.java</p>
  
  <pre><code>public class DBHelper extends SQLiteOpenHelper{
  private static String DB_NAME = "ligas_bd";
  private SQLiteDatabase myDataBase;
  private final Context myContext;
  
  public DBHelper(Context context) {
      super(context, DB_NAME, null, 1);
      this.myContext = context;
  }
  
  public void createDataBase() throws IOException{
      boolean dbExist = checkDataBase();
      if(dbExist){ }
      else {
          this.getReadableDatabase();
          try {
              copyDataBase();
          } catch (IOException e) {
              throw new Error("Error copiando Base de Datos");
          }
      }
  }
  private boolean checkDataBase(){
      SQLiteDatabase checkDB = null;
      try {
          String myPath = DB_PATH + DB_NAME;
          checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
      } catch(SQLiteException e) { }
      if(checkDB != null) {
          checkDB.close();
      }
      return checkDB != null ? true : false;
  }
  
  private void copyDataBase() throws IOException{
      InputStream myInput = myContext.getAssets().open(DB_NAME);
      String outFileName = DB_PATH + DB_NAME;
      OutputStream myOutput = new FileOutputStream(outFileName);
      byte[] buffer = new byte[1024];
      int length;
      while ((length = myInput.read(buffer))&gt;0) {
          myOutput.write(buffer, 0, length);
      }
      myOutput.flush();
      myOutput.close();
      myInput.close();
  }
  
  public void open() throws SQLException{
      try {
          createDataBase();
      } catch (IOException e) {
          throw new Error("Ha sido imposible crear la Base de Datos");
      }
      String myPath = DB_PATH + DB_NAME;
      myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
  }
  
  @Override
  public synchronized void close() {
      if(myDataBase != null)
      myDataBase.close();
      super.close();
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) { }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }
  </code></pre>
  
  <p>I also checked in my phone with root explorer data/data/mypackagename/databases and the database appears there as normal.</p>
  
  <p>My database and the main table have the same name, as you can see in this pic of SQLite database browser:</p>
  
  <p><img src="https://i.stack.imgur.com/es9gY.png" alt="screen capture"></p>
  
  <p>I am not creating the table, I created it before using SQLite Database Browser and I am just trying to read from it</p>
  
  <hr>
  
  <p>I don't know how, but I finally fixed it. I just started again, this time following <a href="http://mobisys.in/blog/2012/01/tutorial-using-database-in-android-applications/" rel="noreferrer">this tutorial</a>. 
  Hope it helps!</p>