Sugar ORM No such table exception

后端 未结 6 1997
后悔当初
后悔当初 2021-01-06 15:50

Sugar ORM works perfectly on Android <5, but on Android 5> it crashes. I am using version 1.4

Please help me.

Error: android.database.sqlite.SQLiteE

相关标签:
6条回答
  • 2021-01-06 16:02

    If you already ran your app with sugar and then later you added a model that gives the 'no such table error', then you need to just update(increase) your database VERSION meta in your AndroidManifest.xml. This solves the problem most of the time when instant run is not the issue. Look at the issue HERE For more insight.

    0 讨论(0)
  • 2021-01-06 16:04

    I was using version 1.3 and faced same problem. But I solved by using gradle version 1.5 and initializing SugarContext.

    In gradle dependencies:

     compile 'com.github.satyan:sugar:1.5' 
    

    In onCreate Method:

     SugarContext.init(this);
    
    0 讨论(0)
  • 2021-01-06 16:10

    please implement hack findById function on your onCreate application class like this

    public class App extends SugarApp {
        @Override
        public void onCreate() {
            super.onCreate();
    
            Audio.findById(Audio.class, (long) 1);
        }
    }
    

    Your audio table will be created

    0 讨论(0)
  • 2021-01-06 16:16

    The message java.lang.NoSuchTable: means that someone tried to call a constructor without any parameters. Adding a default constructor should solve this problem:

    public class User 
    {
        public User() {
        }
        ..
    }
    
    0 讨论(0)
  • 2021-01-06 16:20

    Disabling instant run worked for me.

    0 讨论(0)
  • 2021-01-06 16:21

    And after you disable instant run, make sure you uninstall the app from the phone/emulator before running again.

    0 讨论(0)
提交回复
热议问题