sugar: No such table !!
hi i tried a lot to make sugar database work but it keeps returning NO SUCH TABLE error here is my code:
manifest: `<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="he.hrm.test48">
<application
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="shd.db" />
<meta-data android:name="VERSION" android:value="1" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="he.hrm.test48" />
</application>
</manifest>`
book class:
`public class Book extends SugarRecord { @Unique String isbn; String title; String edition;
// Default constructor is necessary for SugarRecord
public Book() {
}
public Book(String isbn, String title, String edition) {
this.isbn = isbn;
this.title = title;
this.edition = edition;
}
}`
MainActivity
`public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SugarContext.init(getApplicationContext());
}
public void gogo(View view){
Book book = new Book("bbeb","cecf","tegdt");
book.save();
}
}`
it doesn’t work at all and the exception is “no such table: BOOK (code 1): , while compiling: INSERT OR REPLACE INTO BOOK(TITLE,ISBN,ID,EDITION) VALUES (?,?,?,?)”
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 34
This the package where you define your models for example if you define your models in he.hrm.test48.models/Book.java than “he.hrm.test48.models” should be your DOMAIN_PACKAGE_NAME
Clearly.
Check that your class child of Application extends from SugarApp or has inside the following lines
SugarContext.init(this);not use getApplicationContext() insteadthisCheck that your Instant Run is disabled.
3 Check that your
DOMAIN_PACKAGE_NAMEset is correctly.Check that after changes (add lines on Application or disabling Instant Run) you remove app from your phone or clear app data.
Check that version of your bd >= 2 (as stated on the website of the author)
Trying Build->Clean Project->Rebuild Project after changes. It’s helped for me
I had the problem, updating everything and restarting android studio helps. It suddenly started working for me, I can’t explain why exactly it didn’t work before.
Clear the app data & cache or clean install the app
The problem is
DOMAIN_PACKAGE_NAMEyou need to point it to where your models are being kept Quick question , where is yourbookclass?<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="he.hrm.test48" />you sure you placed it inside/he/hrm/test48?And after you disable instant run, make sure you uninstall the app from the phone/emulator before running again.
Here I have some experiences with Sugar ORM library: