user616076
user616076

Reputation: 4001

SQLiteException: no such table

I am using my own SQLite3 database as opposed to creating a new one each time my app runs, as I have a few tables with static data that I am trying to display. I created my database and placed it in my assets folder. I then created my database helper and when I start my app I can open my database without problem but when I try to open my first table using the following code

private Cursor getData() 
{
    try
    {
        myDbHelper = new DatabaseHelper(this);
        SQLiteDatabase db = myDbHelper.getReadableDatabase();
        Cursor cursor = db.query("exhibitor", FROM, null, null, null,null, ORDER_BY);
        startManagingCursor(cursor);
        return cursor;
    }
    catch(SQLiteException e)
    {
        String err = e.toString();
        return null;
    }
}


It throws an error saying android.database.sqlite.SQLiteException: no such table: exhibitor: , while compiling: SELECT _id, EXHIBITOR FROM exhibitor ORDER BY EXHIBITOR but when I check the database exhibitor is there.

What am I missing?

Upvotes: 5

Views: 35113

Answers (10)

Noor Hossain
Noor Hossain

Reputation: 1831

Here is my answer according to the description of @ReivieraKid.

No, Uninstall, No Restart, Just checking the app memory if it is your real database, if return false, then copy the database to the memory again. Then You will All set. But to apply this method, you have to know the minimum size of your database.

https://stackoverflow.com/a/73332470/7608371

Upvotes: 0

Tim Meehan
Tim Meehan

Reputation: 300

Just happened to me. I don't exactly know why but changing the DB_VERSION attribute to a bigger number made it work. The thing is: each time i'm changing the fields of the DB (attributes of the SQLiteDB class), i need to change that number.

Upvotes: 0

Neuron
Neuron

Reputation: 1129

I just had a simple mistake.

Reason:

enter image description here

Solution:

enter image description here

Upvotes: 0

Marlon
Marlon

Reputation: 1897

Just clearing the data did not work for me.

What worked was:

  • Uninstall app
  • Restart device or emulator
  • Disable Instant run (Not just the main group but all individual instant run settings)
  • Build -> Clean Project
  • Build -> Rebuild Project

Upvotes: 1

Vishal Vaishnav
Vishal Vaishnav

Reputation: 3422

Clear Data and uninstall application from your device and re-install application in device...

Settings -> Applications -> Manage Applications -> Your Application Name -> Clear data

Upvotes: 3

Muwaffaq imam
Muwaffaq imam

Reputation: 1

hapend to me once change your DATABASE_VERSION

if your DATABASE_VERSION =1 it will see just three table if your DATABASE_VERSION = 2 it will see just more table but i really didn't know how many

good luck

Upvotes: 0

Ali Hitawala
Ali Hitawala

Reputation: 61

Whenever you create new table in an existing database the table doesnt create because the OnCreate function of database handler will not be called everytime but only if required(like database not initiated). If that is not the case your newly created table actually hasnt created. Clear the data to force the db to instantiate itself.

Upvotes: 6

user1342582
user1342582

Reputation:

Settings -> Applications -> Manage Applications -> (Click on your application) -> Clear data

Upvotes: 18

RivieraKid
RivieraKid

Reputation: 5961

Using SQLiteOpenHelper.onCreate() does not create a new database every time your app starts - rather it creates a database if it does not already exist.

It sounds like you might have an empty database created by or for your helper (if there was no database at all, I might expect a different exception), and your separate database that you created outside of Android. Looks like you and your app are not looking in the same place for your data.

Upvotes: 2

SteD
SteD

Reputation: 14027

Have you moved the database from the assets folder to /data/data/YOUR_PACKAGE/databases/ on the emulator?

This is a good detailed post about moving the database to /data/data/YOUR_PACKAGE/databases/ if it does not exist.

Here is another short and simple solution to it.

Upvotes: 5

Related Questions