question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting no such table error with Sugarorm 1.4 in android

See original GitHub issue

I am getting the following error while I am trying to perform CRUD operations on my db using sugarorm:

E/SQLiteLog: (1) no such table: CONTACT D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.sinha.abhishek.demoapp, PID: 2133
              android.database.sqlite.SQLiteException: no such table: CONTACT (code 1): , while compiling: SELECT * FROM CONTACT WHERE id=? LIMIT 1
                  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                  at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                  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:192)
                  at com.orm.SugarRecord.findById(SugarRecord.java:102)
                  at com.example.sinha.abhishek.demoapp.Contact.<init>(Contact.java:31)
                  at com.example.sinha.abhishek.demoapp.MainActivity$1.onClick(MainActivity.java:48)
                  at android.view.View.performClick(View.java:4785)
                  at android.view.View$PerformClick.run(View.java:19888)
                  at android.os.Handler.handleCallback(Handler.java:739)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5276)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706) 

Can anybody please guide, what might be the probable cause for this and how can it be fixed.

This is my pojo class:

public class Contact extends SugarRecord{

     int contactid;
     String firstName;
     String lastName;
     int age;
     String address;
     String phone;

    public Contact(){
        super();
    }

    public Contact(int contactid, String firstName, String lastName, int age, String address, String phone){
        this.contactid = contactid;
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
        this.address = address;
        this.phone= phone;

    }


}

This is my android manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sinha.abhishek.demoapp">

    <application
        android:name="com.orm.SugarApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">



        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <meta-data
            android:name="DATABASE"
            android:value="hollywoodcontacts.db" />
        <meta-data
            android:name="VERSION"
            android:value="2" />
        <meta-data
            android:name="QUERY_LOG"
            android:value="true" />
        <meta-data
            android:name="DOMAIN_PACKAGE_NAME"
            android:value="com.example.sinha.abhishek.demoapp" />



    </application>

</manifest>

This is my sample code for CRUD operation written within main activity:

Contact  con  = new Contact(101 ,"Abcd","Xyz",22,"myaddress", "9849848943");
con.save();

I have already tried options like:

  1. Disabling instant run
  2. Contact.findById(Contact.class, (long) 1);

but none of then worked for me.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
yohaybncommented, Jan 31, 2017

I has this issue too, and I found that If I change the model fields, I need to change the db version… Even if I deleted the app and reinstall it…

0reactions
aluckenscommented, Jan 7, 2022

The domain package name should match the package where you put the models/entities (class you want to generate table for)

for example: <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example.sinha.abhishek.demoapp.model" />

don’t forget to unistall the app after the changes before running again

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting no such table error with Sugarorm 1.4 in android
The cause is as it says there is not a Table named CONTACT in the database. You are also told that the error...
Read more >
[Fixed]-Android Database Sugar orm no such table
i'm working on a project in android ! And i use Sugar ORM for the interaction with my database.But i think sugar become...
Read more >
SugarORM not creating tables / column not found - Chai Jia Xun
I've been having problems where Sugar simply does not create the tables and I get an error message about tables not being created....
Read more >
satyan/sugar - Gitter
The problem is that I am using Sugar ORM to store task for a todo list ... in the “app” package are created...
Read more >
SugarORM, traps to avoid - Medium
For those who had deal with Android sqlite database before, ... If you don't do this, you may stumble upon “no such table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found