0

I'm facing a very strange error during running android app in Android Studio on emulator. Error is pasted below.

I'm not using SQLite for db. I'm using Shared performances. There is no reference to USER_DATA_TABLE or SQLite in the code.

The only place where I could see reference to USER_DATA_TABLE & SQLite is in /build/generated/mockable-android-23.jar file which is obviously generated by the build process. I deleted entire build folder before building the app and running.

Can any of you experts give me some clue on how to fix it?

The code snippet which access SugarORM is this:

   public void redrawNavMenu() {
    UserDataTable user = UserDataTable.findById(UserDataTable.class, 1L);

findById method used is in SugarORM

public static <T extends SugarRecord<?>> T findById(Class<T> type, Long id) {
    List<T> list = find( type, "id=?", new String[]{String.valueOf(id)}, null, null, "1");
    if (list.isEmpty()) return null;
    return list.get(0);
}

I'm lost here. So where does USER_DATA_TABLE is accessed from if it's not anywhere in the code at all?

Log:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matt.quiz/com.matt.quiz.activities.QuizActivity}: android.database.sqlite.SQLiteException: no such table: USER_DATA_TABLE (code 1): , while compiling: SELECT * FROM USER_DATA_TABLE WHERE id=? LIMIT 1
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.database.sqlite.SQLiteException: no such table: USER_DATA_TABLE (code 1): , while compiling: SELECT * FROM USER_DATA_TABLE WHERE id=? LIMIT 1
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
        at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
        at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1240)
        at com.orm.SugarRecord.find(SugarRecord.java:208)
        at com.orm.SugarRecord.findById(SugarRecord.java:138)
        at com.matt.quiz.activities.QuizActivity.redrawNavMenu(QuizActivity.java:461)
        at com.matt.quiz.activities.QuizActivity.onCreate(QuizActivity.java:194)
        at android.app.Activity.performCreate(Activity.java:6237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Matt
  • 315
  • 2
  • 6
  • 20
  • Before the SQLite error I see Purchase setup error 05-08 18:36:03.032 2573-2573/com.matt.quiz E/Purchase setup: Something going wrong - how to fix this one? – Matt May 08 '16 at 18:04
  • 3
    "I'm not using SQLite for db" -- yes, you are, by means of SugarORM, as you can tell by your stack trace. Please provide a [mcve], which in this case would include the source code to `QuizActivity`. – CommonsWare May 08 '16 at 18:04
  • Tx for quick reply, yes you are right there is reference to SugarORM but again that is in the build files and not my code. I've updated question to show the code snippet where it's called as you can see in the log. Let me know if you require any more code snippets. – Matt May 08 '16 at 18:15
  • 1
    "but again that is in the build files and not my code" -- your code has `UserDataTable user = UserDataTable.findById(UserDataTable.class, 1L);`. Based on your stack trace, `UserDataTable` would appear to extend `SugarRecord`, and that certainly fits with [the Sugar ORM documentation](http://satyan.github.io/sugar/getting-started.html). I do not know why it is not creating the table for you, the way the documentation suggests, as I have never used Sugar ORM. – CommonsWare May 08 '16 at 18:24
  • 1
    I recommend that you read [the documentation](http://satyan.github.io/sugar/index.html), as you seem to be confused as what you are doing. Sugar ORM is "to simplify the interaction with SQLite database". If you do not want to be using SQLite, stop using Sugar ORM. – CommonsWare May 08 '16 at 18:25
  • Not my code, I'm debugging it. – Matt May 08 '16 at 20:14

1 Answers1

0

Finally found answer on my own. It was to do with database version in manifest file. That version requires increment.

Matt
  • 315
  • 2
  • 6
  • 20