title: Android SQLite: No such table error when trying to fetch data from Database
body: <p>I am trying to use an already created DB from a csv file using DB Browser.
  I tried uninstalling and re-installing the app. Also upgraded the DB version and still the same error occurs!
  Checked my DB path and if the file is being created or not.</p>
  
  <p><strong>DatabaseHelper.java</strong></p>
  
  <pre><code>package com.timespro.bookaseat.Model;
  
  import android.content.Context;
  import android.database.Cursor;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteException;
  import android.database.sqlite.SQLiteOpenHelper;
  import android.util.Log;
  
  import com.timespro.bookaseat.Students;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.ArrayList;
  
  
  public class DatabaseHelper extends SQLiteOpenHelper {
  
      private static final String TABLE_NAME1 = "StudentDetails";
  
  
      private static final int DB_VERSION = 5;
      private static String DB_NAME = "data.sqlite";
      private  String DB_PATH;
      private  Context mContext;
      private SQLiteDatabase mDataBase;
      private boolean mNeedUpdate = false;
  
  
      public DatabaseHelper(Context context) {
          super(context, DB_NAME, null, DB_VERSION);
          this.mContext = context;
          DB_PATH = context.getDatabasePath(DB_NAME).getAbsolutePath();
          Log.d("DB_Path",DB_PATH);
      }
  
      public void updateDataBase() throws IOException {
          if (mNeedUpdate) {
              File dbFile = new File(DB_PATH + DB_NAME);
              if (dbFile.exists())
                  dbFile.delete();
  
  
              copyDataBase();
  
              mNeedUpdate = false;
          }
      }
  
      /**
       * Check if the database already exist to avoid re-copying the file each time you open the application.
       * @return true if it exists, false if it doesn't
       */
      private boolean checkDataBase(){
  
          SQLiteDatabase checkDB = null;
  
          try{
              String myPath = DB_PATH + DB_NAME;
              checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
  
          }catch(SQLiteException e){
  
              Log.d("DB","DB doesn't exist!");
  
          }
  
          if(checkDB != null){
  
              checkDB.close();
  
          }
  
          return checkDB != null;
      }
  
  
      /**
       * Copies your database from your local assets-folder to the just created empty database in the
       * system folder, from where it can be accessed and handled.
       * This is done by transferring bytestream.
       * */
      private void copyDataBase() throws IOException{
          Log.d("DB","Database copied!");
          //Open your local db as the input stream
          InputStream myInput = mContext.getAssets().open(DB_NAME);
  
          // Path to the just created empty db
          String outFileName = DB_PATH + DB_NAME;
  
          //Open the empty db as the output stream
          OutputStream myOutput = new FileOutputStream(outFileName);
  
          //transfer bytes from the input file to the output file
          byte[] buffer = new byte[1024];
          int length;
          while ((length = myInput.read(buffer))&gt;0){
              myOutput.write(buffer, 0, length);
          }
  
          //Close the streams
          myOutput.flush();
          myOutput.close();
          myInput.close();
  
      }
      /**
       * Creates a empty database on the system and rewrites it with your own database.
       **/
      public void createDataBase() throws IOException{
  
          boolean dbExist = checkDataBase();
  
          if(dbExist){
              Log.d("DatabaseHelper","DB already exists!");
              //do nothing - database already exist
          }else{
  
              //By calling this method and empty database will be created into the default system path
              //of your application so we are gonna be able to overwrite that database with our database.
              this.getReadableDatabase();
  
              try {
  
                  copyDataBase();
  
              } catch (IOException e) {
  
                  throw new Error("Error copying database");
  
              }
          }
  
      }
  
      private void copyDBFile() throws IOException {
          Log.d("DB","DB File created on phone");
          InputStream mInput = mContext.getAssets().open(DB_NAME);
          //InputStream mInput = mContext.getResources().openRawResource(getResources().getIdentifier("data","raw", getPackageName()));
          OutputStream mOutput = new FileOutputStream(DB_PATH + DB_NAME);
          byte[] mBuffer = new byte[1024];
          int mLength;
          while ((mLength = mInput.read(mBuffer)) &gt; 0)
              mOutput.write(mBuffer, 0, mLength);
          mOutput.flush();
          mOutput.close();
          mInput.close();
      }
  
      public void openDataBase() throws SQLException{
  
          //Open the database
          String myPath = DB_PATH + DB_NAME;
          mDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
          Log.d("DB","DB opened");
      }
  
      @Override
      public void onConfigure(SQLiteDatabase db) {
          super.onConfigure(db);
          db.setForeignKeyConstraintsEnabled(true);
      }
      @Override
      public synchronized void close() {
  
          if(mDataBase != null)
              mDataBase.close();
  
          super.close();
  
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          Log.d("DB","DB created");
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          if (newVersion &gt; oldVersion)
              mNeedUpdate = true;
      }
      public ArrayList&lt;Students&gt; getAllData(){
          ArrayList&lt;Students&gt; students = new ArrayList&lt;&gt;();
          SQLiteDatabase db = this.getWritableDatabase();
          try {
              Cursor res = db.rawQuery("select * from "+TABLE_NAME1, null);
              res.moveToFirst();
              while(res.moveToNext()) {
                  int uid = Integer.parseInt(res.getString(0));   //0 is the number of id column in your database table
                  String name = res.getString(1);
                  String pass = res.getString(2);
                  String city = res.getString(3);
                  String centre = res.getString(4);
                  String inst = res.getString(5);
                  String pro = res.getString(6);
                  String batch = res.getString(7);
                  String days = res.getString(8);
                  String time = res.getString(9);
  
                  Students newStudents = new Students(uid,name,pass,city,centre,inst,pro,batch,days,time);
                  students.add(newStudents);
              }
              res.close();
          }
          catch(SQLiteException sql){
              Log.d("DatabaseError!","No table found!");
          }
          finally {
  
              db.close();
          }
  
          return students;
      }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>error message:</strong>
  E/SQLiteLog: (1) no such table: StudentDetails
  D/DatabaseError!: No table found!</p>