Giter Club home page Giter Club logo

Comments (74)

RodryVazquez avatar RodryVazquez commented on August 23, 2024 5

yes, disable instant Run in android studio

from sugar.

mversteeg3 avatar mversteeg3 commented on August 23, 2024 3

Make sure all of your Sugarized classes are located within the same package. I fixed my issue by moving them to a data.sugar package and changing the DOMAIN_PACKAGE_NAME tag in the manifest to be the fully qualified path of that package

from sugar.

AhmedNMahran avatar AhmedNMahran commented on August 23, 2024 2

I tried above solutions but failed
Finally,Thanks to Allah, i decided to change my class name (it was Mobile, changed to phone) and made version =1 and worked!

from sugar.

Aiuspaktyn avatar Aiuspaktyn commented on August 23, 2024 2

Same problem, fixed using gradle 1.5.0 (before was 2.0.0-beta7)

from sugar.

satyan avatar satyan commented on August 23, 2024 1

As of 1.2 build, we had a requirement of having a constructor with Context paramter.
With 1.3 beta, we removed that constraint. But we still need the default constructor (i.e.) an empty constructor. In absence of which, the tables fail to get created..

from sugar.

divyanshunegi avatar divyanshunegi commented on August 23, 2024 1

Why is this library so buggy ? Satyan please write some more documentation in the website, in example you have created class without context and in another database creation method there you are passing context, please fix these little issues. BTW , it crashes in my device and also shows a white screen when app starts for 100- 200 ms.

from sugar.

felipebonezi avatar felipebonezi commented on August 23, 2024 1

This is not working with GRADLE 2.0.0!!!!!!!

from sugar.

satyan avatar satyan commented on August 23, 2024

Can you share your model class and the android manifest.. Must be a configuration issue.

thanks,
Satya

from sugar.

amaurymuro avatar amaurymuro commented on August 23, 2024

This is my manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:name="com.orm.SugarApp"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.empresaelectrica.MainActivity"
        android:label="Empresa Eléctrica II" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.empresaelectrica.AddAbonado"
        android:label="@string/title_activity_add_abonado"
        android:parentActivityName="com.example.empresaelectrica.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.empresaelectrica.MainActivity" />
    </activity>

    <meta-data
        android:name="DATABASE"
        android:value="abonados.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="com.example" />
</application>

from sugar.

amaurymuro avatar amaurymuro commented on August 23, 2024

2013-10-15-135029_1440x900_scrot

from sugar.

lesiki avatar lesiki commented on August 23, 2024

Hi @amaurymuro. I got the same thing, and like you I had included all 4 optional meta-data tags in my manifest. Removing them fixed it for me (and I don't mind having default db name).

@satyan probably one of these that causes the issue? If it helps, my meta-data config was:

    <meta-data android:name="DATABASE" android:value="myapp.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="com.me.myapp.model" />

from sugar.

awidarto avatar awidarto commented on August 23, 2024

Happened to me too, but turn out that what was wrong was me not following the Getting Started doc.
I changed the VERSION metadata value to 1, because logically I thought I will be creating the first version of the db at installation, but I was wrong, I guess it was supposed to be used in migration process, so I changed back the value to 2 ( as suggested in the doc ), and it just works.

@satyan , maybe more verbose documentation is necessary here, i.e. in that description of VERSION metadata, just to keep people changing that default value of 2 to 1 initially. Thanks !

from sugar.

YaariBoaz avatar YaariBoaz commented on August 23, 2024

guys,
i'm having the same problem...any fixes?

from sugar.

lesiki avatar lesiki commented on August 23, 2024

@DidiPc if it's an option for you, try what I did - drop the meta-data tags. One of them is the cause. @awidarto's comment above makes it sound like the problem is the version metadata, so you could start with that.

from sugar.

satyan avatar satyan commented on August 23, 2024

@DidiPc can you share your manifest and the entity class. Also, try removing the app from the device and running afresh.

If, for some reason, there's an issue with creating table, it would throw this error while performing any db operations.

from sugar.

ciotto avatar ciotto commented on August 23, 2024

Hi, I'm had the same problem and I'm resolved by implementing the empty constructor in my SugarRecord subclass.

from sugar.

ggauravr avatar ggauravr commented on August 23, 2024

@ciotto Right. Just checked with my old code, and the only difference was the absence of empty constructor. It's fixed after adding that !

from sugar.

whoshuu avatar whoshuu commented on August 23, 2024

This issue has been resolved. Closing it.

from sugar.

rdenadai avatar rdenadai commented on August 23, 2024

Just to complement anyone how fall on this page, im using Sugar ORM on version 1.3 ... had the same error, removing thie package tag DOMAIN_PACKAGE_NAME solved for me... im still using the other 3.

from sugar.

bbody avatar bbody commented on August 23, 2024

I am also having a similar problem. If I don't have DOMAIN_PACKAGE_NAME, I get a NullPointerException on my main Activity, if I do have it declared I get the no table error. I have tried with and without the optional attributes but still get those errors. I also have the blank constructor in my model.
(I am using version 1.3)

from sugar.

rdenadai avatar rdenadai commented on August 23, 2024

@bbody how are you import the lib? Using gradle?
In my test im not using gradle, im using eclipse latest with adt latest also! (im not using bundle because bundle has a problem with annotations).

from sugar.

bbody avatar bbody commented on August 23, 2024

I am using Gradle. I am exploring other libraries at the moment.

from sugar.

rdenadai avatar rdenadai commented on August 23, 2024

@bbody since im not using gradle, cant say that could be a issue to that... don't think so but.
Assure that your classes have an empty constructor as the guys said above.

from sugar.

bbody avatar bbody commented on August 23, 2024

I have followed all the aforementioned solutions to no avail.

from sugar.

rdenadai avatar rdenadai commented on August 23, 2024

@bbody could you share yours package tags used on android manifest? And one of your classes that extend SugarRecord?
I'm also realized that my android:name="VERSION" android:value="1" isn't 1 (one)!!! Is 2 (two) ... putting 2 on this tag solve another issue i was having...
This must be done even if i install the app from zero!

from sugar.

ECriew1928 avatar ECriew1928 commented on August 23, 2024

@bbody i also tried everything suggested without success, in the end i deleted the applications cache and now it works

from sugar.

worker8 avatar worker8 commented on August 23, 2024

I'm facing this problem too and the version used is 1.3. I managed to solved it by removing the Constructor of the model class completely, hope it helps someone with similar issue!

from sugar.

nesasivan avatar nesasivan commented on August 23, 2024

where we need to use the constructor

from sugar.

Raguking avatar Raguking commented on August 23, 2024

where we need to use the constructor??

from sugar.

mouhsinelonly avatar mouhsinelonly commented on August 23, 2024

this should really be fixed +1

from sugar.

ksrpraneeth avatar ksrpraneeth commented on August 23, 2024

I was having the same issue i solved it by adding

  1. public empty constructor (Public constructor is must.)
  2. Increasing the VERSION in manifest file to '20'(can be anything)

from sugar.

HosseinKurd avatar HosseinKurd commented on August 23, 2024

Is it possible to Add new table in new version released without removing older version ??

from sugar.

fbngrm avatar fbngrm commented on August 23, 2024

Solved by changing the database name:
<meta-data android:name="DATABASE" android:value="ae_qt_01.db" />
to:
<meta-data android:name="DATABASE" android:value="ae01.db" />

from sugar.

HosseinKurd avatar HosseinKurd commented on August 23, 2024

@3ct0m0rph Change DB Name ? Lose Previous Tables And Rows

from sugar.

fbngrm avatar fbngrm commented on August 23, 2024

@HosseinKurd To get it working initially.

from sugar.

HosseinKurd avatar HosseinKurd commented on August 23, 2024

@3ct0m0rph So How to add new table to DB witout create new DB file ?

from sugar.

sarathvallathol avatar sarathvallathol commented on August 23, 2024

I am using Gradle worked for firs time but next day tried its crashing saying"SQLiteException: no such table _sugar". then after reading all these changed my version from 3 to 5 worked. i don't know why. so i need to change y version daily ? please help

And also I cant down grade the version to below 3

from sugar.

johnelevado avatar johnelevado commented on August 23, 2024

Like the others, i fixed mine with an empty constructor. Just create it in your SugarRecord sub class

from sugar.

leohgz avatar leohgz commented on August 23, 2024

Mine works putting the:

   # <meta-data android:name="DATABASE" android:value="sugar.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="own.leo.libreria.sqlite" />

outside the "application" tag
Thats weird. The other thing that works for me. Leaving to ="2" the version of database, as the website suggests.

from sugar.

krazykira avatar krazykira commented on August 23, 2024

I am getting the same exception and none of the above solutions worked for me

10-09 11:30:21.511 4326-4831/com.example.app E/SQLiteLog: (10) Failed to do file read, got: 0, amt: 100, last Errno: 2
10-09 11:30:26.506 4326-4831/com.example.app E/SQLiteLog: (1) no such table: IMAGE
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:838)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:  Caused by: android.database.sqlite.SQLiteException: no such table: IMAGE (code 1): , while compiling: SELECT * FROM IMAGE
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:886)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:497)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1238)

This happens when i add GPU image Android Library. I am using Gradle and Android Studio. Also once i remove GPU image this issue is solved. So i don't know whats the conflict.

I have also posted a question related to this exception on stackoverflow

from sugar.

farmazon3000 avatar farmazon3000 commented on August 23, 2024

I have the same issue.

@satyan "But we still need the default constructor (i.e.) an empty constructor. In absence of which, the tables fail to get created.." why? Doesn't java create one by default?

from sugar.

ontur00 avatar ontur00 commented on August 23, 2024

I have a problem when I delete the application file database. Then there is an error android.database.sqlite.SQLiteException: no such table Province, but when I push a database to emulator of all CRUD operations are performed.

Before i was create database table invoking any entity object like
Province province= new Province();
province.save(); - now this cause SQLiteException no such table :|

My entity :
extends SugarRecord
have basic construtor without parameters

Link how look manifest
http://wklej.org/hash/d6732855df6/

from sugar.

sibelius avatar sibelius commented on August 23, 2024

@ontur00 which version of sugar are you using? why are you deleting the database file?

from sugar.

ontur00 avatar ontur00 commented on August 23, 2024

compile 'com.github.satyan:sugar:1.3'
Beacuse i trying method which check if( database != exist ) then i want create .db file

from sugar.

sibelius avatar sibelius commented on August 23, 2024

try to use 1.4 or master version

from sugar.

ontur00 avatar ontur00 commented on August 23, 2024

I need only change 1.3 to 1.4 and extends SugarRecord - without < T > ?

from sugar.

ontur00 avatar ontur00 commented on August 23, 2024

I have problem manifest

Error:(16, 23) No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher').

from sugar.

sibelius avatar sibelius commented on August 23, 2024

do you have a drawable ic_launcher?

from sugar.

ontur00 avatar ontur00 commented on August 23, 2024

I try at new TestProject.
I add
compile 'com.github.satyan:sugar:1.4' - sync project - to gradle
new class at package where is my activity (com.example.user.testsugar1_4 )
in my main activity Book book = new Book("isbn123", "Title here", "2nd edition");
Book.save(); and :

Exception :
Caused by: java.lang.NullPointerException: SugarContext has not been initialized properly. Call SugarContext.init(Context) in your Application.onCreate() method and SugarContext.terminate() in your Application.onTerminate() method.

I use this tutoriall - https://android-arsenal.com/details/1/337

http://pastebin.com/iB1J1KRj - main activity
http://pastebin.com/dgdy7eiX - manifest
http://pastebin.com/jESs2KjQ - gradle

from sugar.

sibelius avatar sibelius commented on August 23, 2024
public class TestProjectApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        SugarContext.init(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        SugarContext.terminate();
    }

}

from sugar.

ontur00 avatar ontur00 commented on August 23, 2024

First Thank you very much for help @sibeliusseraphini

I fixed I use a 1.3, I had a mistake in the manifest

meta-data android: name = "DOMAIN_PACKAGE_NAME" android: value = "com.example.user.wrongPackage.Model" - wrong PACKAGE

Advice to other check if you have a well-configured manifest

from sugar.

RodryVazquez avatar RodryVazquez commented on August 23, 2024

I just to have the same problem, I fixed by adding an empty contructor, and compile with the 1.3 Sugar orm version and rainstalled the app, and before new testing run cleanner in device and clear cache.
my ManifestFile looks like :

meta-data android:name="DATABASE" android:value="MyDb.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="com.example.DemoApp.Models"

Models content a Sugar model classes for example => example extends SugarRecord

from sugar.

krazykira avatar krazykira commented on August 23, 2024

For me this error occured because i had Multidex enabled and i was using a lot of libraries around 20 of them and it was a very big project with a lot of classes. I debugged and went through the source code and i confirmed it there that the classes that extended sugar record were never found so in the end i added my classes explicitly into the source code in order to get my project to work.

I don't know if this would help other but it certainly something that the devs should look into. Try adding the project as library project and try debugging the source code and you will find the same issue.

from sugar.

miladna7 avatar miladna7 commented on August 23, 2024

i did this thing:
change DOMAIN_PACKAGE_NAME = not working
change VERSION = not working
change DATABASE = working
so i think change the db name may help u in this case.

from sugar.

Gujarats avatar Gujarats commented on August 23, 2024

Yes I was having the same issue, @miladna7 Thanks man your suggestion works.
But I wonder why it can't use the same database?

from sugar.

sibelius avatar sibelius commented on August 23, 2024

it is fixed on master and on 1.5 version

from sugar.

aubertdavy avatar aubertdavy commented on August 23, 2024

Hi, no changment, i've got the same error..

from sugar.

Gujarats avatar Gujarats commented on August 23, 2024

@aubertdavy try to change the name of your database or update to the version 1.5

from sugar.

aubertdavy avatar aubertdavy commented on August 23, 2024

@Gujarats yes that's what i did !!
I upgrated to 1.5, removed my app, changed my db name .. and no changment

from sugar.

aubertdavy avatar aubertdavy commented on August 23, 2024

Ok i solved my problem extending SugarApp and passing application context (and not base context) on create overriding method

from sugar.

cdaringe avatar cdaringe commented on August 23, 2024

@aubertdavy, can you be more specific?

from sugar.

aubertdavy avatar aubertdavy commented on August 23, 2024

@cdaringe
Init SugarContext in a derived Application class, passing application base context solved my problem.

from sugar.

aubertdavy avatar aubertdavy commented on August 23, 2024

public class MySugarApp extends Application {
@OverRide
public void onCreate() {
super.onCreate();
SugarContext.init(getApplicationContext());
}
}

from sugar.

cdaringe avatar cdaringe commented on August 23, 2024

i'm sorry to be a total rookie on this (i rarely code java), but no where in my current app do I use Application explicitly (perhaps implicitly?). Even if so, I'd like to write some unit tests--I'm unsure how'd I'd get the context otherwise if there'd be no Context in the test suite.

thanks for the tip.

from sugar.

cdaringe avatar cdaringe commented on August 23, 2024

nm, @aubertdavy, i did figure out how to do that. still gives the error, though, unforunately

Caused by: android.database.sqlite.SQLiteException: no such table: CUSTOMER (code 1): , while compiling: INSERT OR REPLACE INTO CUSTOMER(EMAIL,ID,NAME) VALUES (?,?,?)

from sugar.

RodryVazquez avatar RodryVazquez commented on August 23, 2024

try, reinstall the app in the phone, in some cases its necesary, I never use application context to initialize sugar context in my apps

from sugar.

firaskafri avatar firaskafri commented on August 23, 2024

Instant Run now works #564

from sugar.

truongvnse03130 avatar truongvnse03130 commented on August 23, 2024

i have the same problem, but i fixed by:

  • Write a subclass extends Application like this:

public class SugarORMApplication extends Application {
@OverRide
public void onCreate() {
super.onCreate();
SugarContext.init(this);
}
@OverRide
public void onTerminate() {
super.onTerminate();
SugarContext.terminate();
}
}

  • Add android:name="com.....SugarORMApplication" (to class above) in Manifest file and is fixed

from sugar.

firaskafri avatar firaskafri commented on August 23, 2024

@felipebonezi please check #564

from sugar.

amrishodiq avatar amrishodiq commented on August 23, 2024

I tried to disable instant run on android studio 2.1.2 but still have no luck.
But actually succeed when using gradle 1.5.0.

classpath 'com.android.tools.build:gradle:1.5.0'

on project's build.gradle.

I hope the patch will be released soon.

from sugar.

bishwash-adhikari avatar bishwash-adhikari commented on August 23, 2024

This may help :
correct :
<meta-data android:name="DATABASE" android:value="cal.db" />
Error:
<meta-data android:name="DATABASE" android:value="cal_bi.db" />

from sugar.

billgockeler avatar billgockeler commented on August 23, 2024

updating build.gradle to 'com.github.satyan:sugar:1.5' fixed it for me

from sugar.

cbedoy avatar cbedoy commented on August 23, 2024

Not working with kotlin using

'com.github.satyan:sugar:1.5'

from sugar.

Lim-Jerico11 avatar Lim-Jerico11 commented on August 23, 2024

I have a problem java.lang.NullPointerException: SugarContext has not been initialized properly. Call SugarContext.init(Context) in your Application.onCreate() method and SugarContext.terminate() in your Application.onTerminate() method.

from sugar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.