I am getting the No Such table
exception when i am Using Sugar ORM with GPU image Android Library. I am using Gradle and Android Studio. Once i remove GPU image
Disable your instant Run go to File > settings > Build, Execution, Deployment > Instant Run
I had this problem. I executed all suggestions posted here. But neither worked. Then I applied all together, and finally got rid of that problem. What I did-
1. Disabled instant run. (as Parth Vora said.)
2. Then I added the following class-
import android.app.Application;
import android.content.res.Configuration;
import com.orm.SugarApp;
import com.orm.SugarContext;
public class SugarOrmTestApplication extends SugarApp {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
public void onCreate() {
super.onCreate();
SugarContext.init(getApplicationContext());
Book.findById(Book.class, (long) 1);
}
@Override
public void onLowMemory() {
super.onLowMemory();
}
@Override
public void onTerminate() {
super.onTerminate();
}
}
3. Modified manifest file-
<application
//Added the following lines-
android:name="SugarOrmTestApplication">
<meta-data android:name="DATABASE" android:value="sugar_example_new.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
</application>
And this is my model class-
public class Book extends SugarRecord {
String title;
String edition;
public Book(){
}
public Book(String title, String edition){
this.title = title;
this.edition = edition;
}
}
Now my application works good.
To create model tables, I use to execute this for all my models once my Application starts:
Book.findById(Book.class, (long) 1);
Car.findById(Car.class, (long) 1);
My Application extends SugarApp, so this forces Sugar to create all tables.
On the other hand, to update your database, you have to change your version to 2.
And finally, having an empty constructor is a must.
Hope this helps! ;)
I had the same problem and solved it not by disabling instant run but by changing my:
<meta-data android:name="VERSION" android:value="1" />
to
<meta-data android:name="VERSION" android:value="2" />
Since the lowest value should be 2
If you are using Android studio 2.0
Having same issue!
So instant run is not compatible with Sugar ORM
Enjoy!
Resolved
I don't know but the SugarDb.onCreate is not called. So put this code in MainActivity.onCreate and the Sugar ORM will work
SugarDb db = new SugarDb(this);
db.onCreate(db.getDB());