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

4
  • 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? Commented Jul 20, 2011 at 14:53
  • forget accessing it.. when i get the sqlite file thru ddms ,, i find configTable created but tablename not there Commented Jul 20, 2011 at 14:58
  • Did you try to insert something in tablename? You should receive an exception. Would you copy/paste it here? Commented Jul 20, 2011 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(?, ?); Commented Jul 20, 2011 at 15:35

5 Answers 5

11

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

same problem i faced , isolved using same trick.

Sign up to request clarification or add additional context in comments.

4 Comments

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
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???
@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.
It's the solution for me on android 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.

Comments

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

Comments

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"

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.