2

I’m using Preload Database with multiple Tables with data already present in tables in all tables. My Error logcat shows “no such table: cake (code 1 SQLITE_ERROR): , while compiling: select * from cake at” but actually table and its data are already there.

I have also checked copied database in Phone, it was there but in code it is displaying the error above.

How to solve this problem??

Note : This error occurs only in Google Pixel Phone..

AndroidRuntime: FATAL EXCEPTION: main Process: com.ebizzapps.swadishtcookingrecipesinhindi, PID: 9060 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebizzapps.swadishtcookingrecipesinhindi/com.ebizzapps.swadishtcookingrecipesinhindi.DetailRecipe}: android.database.sqlite.SQLiteException: no such table: cake (code 1 SQLITE_ERROR): , while compiling: select * from cake at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: android.database.sqlite.SQLiteException: no such table: cake (code 1 SQLITE_ERROR): , while compiling: select * from cake at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1408) at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1347) at com.ebizzapps.swadishtcookingrecipesinhindi.DBHelper.getDatas(DBHelper.java:162) at com.ebizzapps.swadishtcookingrecipesinhindi.DetailRecipe.onCreate(DetailRecipe.java:161) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

  • 2
    it seems like there is notable `cake` according to logcat – Rahul Chokshi Sep 08 '18 at 05:01
  • Welcome to Stack Overflow. Be sure to read the error message carefully. Also show a minimal example that causes this error. – Code-Apprentice Sep 08 '18 at 05:05
  • Did place your database file on the assets folder under a directory called databases `/assets/databases/database.db` – Rahul Chokshi Sep 08 '18 at 05:07
  • i have the databases in assets folder do I need to create databases ? – Ahmad Arslan Oct 03 '18 at 13:16
  • I ran into the same issue. My app worked prior to Android P. I know the tables are there but I get this same sqlite exception saying there are not such tables. If you find a solution please message me. – Luis Oct 05 '18 at 12:16
  • There's a solution here: https://stackoverflow.com/questions/50476782/android-p-sqlite-no-such-table-error-after-copying-database-from-assets – Luis Oct 05 '18 at 12:17
  • The solution that ended up working for me is here: https://stackoverflow.com/a/51953955/1172181 – Luis Oct 05 '18 at 12:30

3 Answers3

3

See this stackoverflow post: Android P SQLite Pragma Log.

Disable write ahead logging on your SQLiteOpenHelper's onOpen method, like this:

@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    db.disableWriteAheadLogging();
}
Luis
  • 3,451
  • 1
  • 27
  • 41
0

Create a table and name it as "cake".As per the error log

enter image description here

there is no such table "cake".I think you have forgot to place your database to asset folder.

Thank you

Sana
  • 456
  • 3
  • 9
0

From your Error Log.

no such table: cake (code 1 SQLITE_ERROR): , while compiling: select * from cake at

Its mentioned that there is no any table with name cake . So before fetching value from table ensure that there is a table with this name already exist in database.

Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
  • The error message is misleading. I'm getting the same error but I know the tables exist plus the app worked fine on previous Android versions. – Luis Oct 05 '18 at 12:14