4

ISSUE (LogCat)

sqlite returned: error code = 1, msg = no such table ...

android.database.sqlite.SQLiteException: no such table: ....

CODE

public void onCreate(SQLiteDatabase db) {
    Log.v("SQLAdapter","onCreate(SQLiteDatabase db)");
    db.execSQL("CREATE TABLE "+tablename
            +" ("
            +col1+ " TEXT PRIMARY KEY , "
            +col2+ " TEXT , "
            +col3+ " TEXT , "
            +col4+ " TEXT , "
            +col5+ " TEXT , "
            +col6+ " TEXT , "
            +col7+ " TEXT , "
            +col8+ " TEXT "
            +")");
    db.execSQL("CREATE TABLE "+configTable
            +" ("
            +colName+ " TEXT PRIMARY KEY , "
            +colValue+ " TEXT "
            +")");
    
    ContentValues cv=new ContentValues();
    cv.put(colName, "updated");
    cv.put(colValue, "-1");
    db.insert(configTable, colName, cv);
}

RESULT

configTable is being created

tablename is not being created

Community
  • 1
  • 1
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
  • Where is the value of `tablename` set? I can't see it in your code. Also, you code never tried to access `tablename`, so what throws the error? – David Snabel-Caunt Jul 20 '11 at 14:53
  • forget accessing it.. when i get the sqlite file thru ddms ,, i find configTable created but tablename not there – Sherif elKhatib Jul 20 '11 at 14:58
  • Did you try to insert something in tablename? You should receive an exception. Would you copy/paste it here? – Shlublu Jul 20 '11 at 15:26
  • 07-21 03:32:23.224: ERROR/Database(11222): android.database.sqlite.SQLiteException: no such table: config: , while compiling: INSERT INTO config(colName, colValue) VALUES(?, ?); – Sherif elKhatib Jul 20 '11 at 15:35

5 Answers5

11

simply Change Your Databse name in Data base class which you implemented Using SQliteDatabase

same problem i faced , isolved using same trick.

sravan
  • 5,303
  • 1
  • 31
  • 33
  • I can not test it anymore because I decided not to use SQL in any of my projects. Please if someone tests this and it turns to be wrong, tell me. For now! +1 and tick for you. thank you really – Sherif elKhatib Dec 22 '11 at 12:05
  • Happened the same here. I have 3 Classes ("X"DbHelper) inheriting from BaseDBHelper which has the database name. I've done what you mentioned and now it works... Is very estrange, isn't it??? – cesards Oct 16 '12 at 15:51
  • @m3n0R very weird. I know I solved this by creating one SQL class for each table! But now am looking at this answer and the feedback. seems he got the right solution. – Sherif elKhatib Jan 28 '13 at 10:02
  • It's the solution for me on android 10 – vahid sabet Jun 21 '20 at 05:10
1

I had the same exception while testing on a real device. After I added a new table to my database I had to uninstall an older app version from the device . Only then the onCreate() method from the SQLiteOpenHelper subclass was called again.

sbo3000
  • 176
  • 1
  • 7
0

Same problem. Fix the problem by deleting away the old xxx.db created by using the adb command

adb shell rm /data/data/xxx.db

ken
  • 13,869
  • 6
  • 42
  • 36
0

"no such table" problem worked out!

When you are using a database.db, Android create also another file named database (without extension) with an android_metadata table.

Finally, I solved just changing DB_NAME ="mydb" with DB_NAME="mydb.db"

adev
  • 367
  • 1
  • 3
  • 20
0

I also faced the "no such table" problem. This is no problem from the database or table but from your application.

just you have reinstall our application and everything should be fine.

Ole Albers
  • 8,715
  • 10
  • 73
  • 166
MalhotraUrmil
  • 88
  • 1
  • 10