Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Exception: no such table Error [duplicate]

Tags:

android

sqlite

Possible Duplicate:
Android Sqlite - “No Such Table” Error

We are trying to develop an application on Android. We are using SQLite database and on phone we are getting

SQLiteException:no such table.

It is working fine on simulator.

Can anyone provide any input on this?

like image 801
MySQL DBA Avatar asked Jun 01 '09 10:06

MySQL DBA


3 Answers

If you don't specify the database file name correctly I believe it falls back to creating an empty database. This is generally the cause of 'table not found'. Check your path and database file name.

like image 99
Jay Avatar answered Nov 04 '22 02:11

Jay


I had faced a different flavour of the same problem.

I was getting no such table error when I try to insert.

Before inserting, the code was calling

mDb = mDbHelper.getWritableDatabase(); 

getWritableDatabase() , when called first time will call onCreate()

I had my SQL query to create the table within this oncreate method

public void onCreate(SQLiteDatabase db) {

            db.execSQL(DATABASE_CREATE);
            Log.v("INFO1","creating db");
            //Toast.makeText(mCtx, "created", Toast.LENGTH_SHORT).show();
        }

So for me what had happened was, the db was successfully created when the application was first run but no table due to some other errors. Later whenever the application is run, onCreate() is never called as db is already there and thus no table created, so all further SQL commands failed.

So I moved creating table out of onCreate() , and now its working

like image 35
png Avatar answered Nov 04 '22 03:11

png


Some people have been able to solve the problem using the steps mentioned here. It seems to me that this problem exists on certain versions of Android 2.2. I have incorporated this change in my code, though I'm still looking for Beta testers with to see if it actually works.

like image 2
Abhinav Manchanda Avatar answered Nov 04 '22 01:11

Abhinav Manchanda