Reputation: 637
I'm playing around with Sqlite but it seems like the database is not found....it actually blames the table but I dont believe that.
Error: android.database.sqlite.SQLiteException: no such table: food (code 1): , while compiling: SELECT * FROM food
Here is my database: /data/data/com.haze.purple.foodorcars/databases/foods.db I have double checked this with rootExplorer amd the file is there. I have also downloaded this db file in windows and tried an sqlite editor and I can find the table food....so it must be the code.
So I believe that it's the file that somehow is not found. Here is my DatabaseHelper:
public CarsOrFoodDatabaseHelper(Context appContext) {
super(appContext, DATABASE_FILENAME, null, DB_VERS);
this.context = appContext;
DATABASE_FILENAME = context.getResources().getString(R.string.databasefile);
}
Should I use context or applicationContext for my dbhelper?
Can I print somewhere the actual file and path to db that is used in my dbhelper?(stupid question maybe:)
Upvotes: 0
Views: 59
Reputation: 1705
The problem in above code is you are setting DATABASE_FILENAME to some other value after calling super(...) method. Make sure that your DATABASE_FILENAME will be initialized outside the constructor or you declare it as static final string in the same class.
Your code should look like as follows.
static final String DATABASE_FILENAME="foods";
public CarsOrFoodDatabaseHelper(Context appContext) {
super(appContext, DATABASE_FILENAME, null, DB_VERS);
}
Upvotes: 1