3

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.SQLiteException: no such table: AUDIO (code 1): , while compiling: SELECT * FROM AUDIO

proguard-rules.pro

-keep class me.lobanov.mp3downloadsfree.models.** { *; }

My model class:

package me.lobanov.mp3downloadsfree.models;

import com.orm.SugarRecord;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class Audio extends SugarRecord {
    private long aud_id;
    private String aud_artist;
    private String aud_title;
    private String aud_url;
    private long aud_duration;

    public Audio() {
    }

    public Audio(long aud_id, String aud_artist, String aud_title, String aud_url, long aud_duration){
        this.aud_id = aud_id;
        this.aud_artist = aud_artist;
        this.aud_title = aud_title;
        this.aud_url = aud_url;
        this.aud_duration = aud_duration;
    }
}

My application class:

public class App extends SugarApp {
    @Override
    public void onCreate() {
        super.onCreate();
    }
}

My manifest:

<meta-data android:name="DATABASE" android:value="mp3downloadsfree.db" />
        <meta-data android:name="VERSION" android:value="5" />
        <meta-data android:name="QUERY_LOG" android:value="true" />
        <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="me.lobanov.mp3downloadsfree.models" />
eightShirt
  • 1,457
  • 2
  • 15
  • 29
Igor Lobanov
  • 345
  • 3
  • 12
  • did you find a solution? i had been using sugar for some time now and it just started giving this error, everything seems fine, all configurations are correct, every sugar class has public default constructor – Aditya Chauhan Apr 09 '16 at 07:53
  • I write my own class without sugar orm – Igor Lobanov Apr 09 '16 at 16:40
  • 1
    if you have recently upgraded to Android Studio 2.0 then the Instant Run feature causes problems with the SQL table creation which will lead on to the exception you are having. Disable Instant run to fix – Dean Wild Apr 11 '16 at 17:07
  • @DeanWild bro, thank you – TheLoy Apr 13 '16 at 09:43

6 Answers6

14

Disabling instant run worked for me.

Pradeep VR
  • 166
  • 1
  • 5
3

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.

Akah
  • 1,389
  • 14
  • 19
1

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

kospol
  • 377
  • 3
  • 9
1

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);
Oomph Fortuity
  • 5,710
  • 10
  • 44
  • 89
Quraishi sazid
  • 91
  • 1
  • 12
0

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

baroni
  • 176
  • 8
0

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() {
    }
    ..
}