Note that there are some explanatory texts on larger screens.

plurals
  1. PONo such table exists -Sqlite error when writing to database in android
    text
    copied!<p>I am trying to write to a table in my sqlite database in android the code I am using is as follows:</p> <pre><code>DBH = new DatabaseHelper(this); try { DBH.createDataBase(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DBH.getWritableDatabase().rawQuery("insert into profile (_id, FirstName) values (1, 'Dave')", null); DBH.close(); </code></pre> <p>DBH is my database helper class and it creates the database just fine and I've even been able to read from the database so i know its there. The table im trying to write to is profile and i am certain that it does in fact exist but every time i run this i get this error:</p> <pre><code>sqlite returned: error code = 1, msg = no such table: profile </code></pre> <p>I've tried reading from this table and have been able to get results so I'm pretty much stumped. Anyone got any ideas?</p> <p>Edit: As requested this is my Database helper class</p> <pre><code>public class DatabaseHelper extends SQLiteOpenHelper { private static String DB_PATH = "/data/data/com.ProjectZeus.FitnessWire/databases/"; private static String DB_NAME = "fitnesswire.db"; private SQLiteDatabase myDB; private Context myContext; public DatabaseHelper(Context context) { super(context,DB_NAME, null, 1); this.myContext = context; } public void createDataBase() throws IOException{ boolean check = checkDataBase(); if(check){ //Log.e("Check", "Database exists"); }else{ this.getReadableDatabase(); try{ copyDataBase(); }catch(Exception e){ throw new Error("Error copying database"); } } } 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(); } private boolean checkDataBase() { SQLiteDatabase checkdb = null; try{ String myPath= DB_PATH + DB_NAME; checkdb = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ Log.e("checkDataBase()", "Database doesntexist yet"); } if(checkdb != null){ checkdb.close(); } return checkdb != null ? true : false ; } public void openDataBase() throws SQLException { String myPath = DB_PATH + DB_NAME; myDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Override public synchronized void close(){ if(myDB != null){ myDB.close(); } super.close(); } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } </code></pre> <p>} </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload