title: Table missing from database in sqlite
body: <p>I have an sqlite database stored in <code>assets/databases/minitest.db</code> and I try to copy it to the local filesystem from the assets folder and then open it. </p>
  
  <p>When I open it I get a table not found exception. </p>
  
  <p>I am pretty sure it's not something wrong with the database itself because when I open it with an sqlite viewer it looks just fine. I've been googling this problem for about 2 hours now and I have seen a bunch of similar questions but none of their solutions seem to work so I really don't know what to do. </p>
  
  <p>Code:</p>
  
  <pre><code>mydatabase = new DataBaseHelper(c).myDataBase;
  Cursor mCursor = mydatabase.rawQuery("SELECT third FROM Trigrams WHERE first='" + first.toLowerCase() + "' AND second ='" + second.toLowerCase() + "' ORDER BY freq DESC LIMIT 0,3", null);
  </code></pre>
  
  <p>Complete DataBaseHelper:</p>
  
  <pre><code>class DataBaseHelper extends SQLiteOpenHelper {
      private Context mycontext;
      private static final String DB_NAME = "minitest.db";    
      private static final String DB_PATH = "/data/data/" +       BuildConfig.APPLICATION_ID + "/databases/";
      private static final int DB_VERSION = 3;
      public SQLiteDatabase myDataBase;
  
      public DataBaseHelper(Context context) throws IOException {
          super(context, DB_NAME, null, DB_VERSION);
          this.mycontext = context;
          boolean dbexist = checkdatabase();
          if (dbexist) {
              System.out.println("Database exists");
              opendatabase();
          } else {
              System.out.println("Database doesn't exist");
              createdatabase();
              opendatabase();
          }
      }
  
      public void createdatabase() throws IOException {
          boolean dbexist = checkdatabase();
          if (dbexist) {
              System.out.println(" Database exists.");
          } else {
              this.getReadableDatabase();
              try {
                  copydatabase();
              } catch (IOException e) {
                  throw new Error("Error copying database");
              }
          }
      }
  
      private boolean checkdatabase() {
  
          boolean checkdb = false;
          try {
              String myPath = DB_PATH + DB_NAME;
              File dbfile = new File(myPath);
              checkdb = dbfile.exists();
          } catch (SQLiteException e) {
              System.out.println("Database doesn't exist");
          }
          return checkdb;
      }
  
      private void copydatabase() throws IOException {
          //Open your local db as the input stream
          InputStream myinput = mycontext.getAssets().open("databases/" + 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 byte to inputfile to outputfile
          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();
      }
  
      public void opendatabase() throws SQLException {
          //Open the database
          String mypath = DB_PATH + DB_NAME;
          myDataBase = SQLiteDatabase.openDatabase(mypath, null, SQLiteDatabase.OPEN_READONLY);
      }
  
      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) {
          if (newVersion &gt; oldVersion)
              try {
                  copydatabase();
              } catch (IOException e) {
                  e.printStackTrace();
              }
      }
  }
  </code></pre>
  
  <p>Error log:</p>
  
  <pre><code>E/SQLiteLog: (1) no such table: Trigrams
  E/InputEventReceiver: Exception dispatching input event.
  E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
  E/MessageQueue-JNI: android.database.sqlite.SQLiteException: no such table: Trigrams (code 1): , while compiling: SELECT third FROM Trigrams WHERE first='a' AND second ='baby' ORDER BY freq DESC LIMIT 0,3
      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
      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.&lt;init&gt;(SQLiteProgram.java:58)
      at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
      at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
      at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1355)
      at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1294)
      at com.chair49.sentimentkeyboard.analysis.NextWord.getNextWords(NextWord.java:38)
      at com.chair49.sentimentkeyboard.SimpleIME.onKey(SimpleIME.java:125)
      at android.inputmethodservice.KeyboardView.detectAndSendKey(KeyboardView.java:828)
      at android.inputmethodservice.KeyboardView.repeatKey(KeyboardView.java:1371)
      at android.inputmethodservice.KeyboardView.onModifiedTouchEvent(KeyboardView.java:1281)
      at android.inputmethodservice.KeyboardView.onTouchEvent(KeyboardView.java:1214)
      at android.view.View.dispatchTouchEvent(View.java:9337)
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2554)
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2198)
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2554)
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2198)
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2554)
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2198)
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2554)
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2198)
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2554)
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2198)
      at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2432)
      at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1746)
      at android.app.Dialog.dispatchTouchEvent(Dialog.java:787)
      at android.inputmethodservice.SoftInputWindow.dispatchTouchEvent(SoftInputWindow.java:93)
      at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2393)
      at android.view.View.dispatchPointerEvent(View.java:9557)
      at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4263)
      at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4102)
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3644)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3697)
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3663)
      at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3789)
      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3671)
      at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3846)
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3644)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3697)
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3663)
      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3671)
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3644)
      at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5955)
      at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5929)
      at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5890)
      at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6058)
      at android.view.InputEventReceiver.dispatchInputEvent(Inp
  07-14 14:12:42.161 14083-14083/com.chair49.sentimentkeyboard E/AndroidRuntime: FATAL EXCEPTION: main
  </code></pre>