Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to instantiate Sugar ORM database

I have imported the latest version of android Sugar ORM library into eclipse and have referenced it from my project. To the manifest i have added the following meta tags:

   <meta-data
        android:name="DATABASE"
        android:value="venn_app.db" />
    <meta-data
        android:name="VERSION"
        android:value="7" />
    <meta-data
        android:name="QUERY_LOG"
        android:value="true" />

This is my POJO object:

public class Event extends SugarRecord<Event> {

int id;
LatLng latLng = new LatLng(0,0);
String name;
Long startTime = new Long(0);
boolean isSelected = false;
boolean isCheckedIn = false;

public Event(){ }

public Event(int id, String name, LatLng latLng){
    startTime = System.currentTimeMillis(); // divide by 1000 to get seconds
    this.id = id;
    this.latLng = latLng;
    this.name = name;
    isSelected = false;
    isCheckedIn = false;
}

This Call always results with null pointer exception even though the object is not null. Do i need to instantiate the Database?

            try {

                Event event = new Event(0, name, lat, longi);
                Log.d("sugar", event.toString());
                event.save();
            } catch (Exception e) {

                Log.d("sugar", "failed to add an event");
                Log.d("sugar", e.toString());
            }

I am using Nexus 7.

like image 512
JY2k Avatar asked Dec 06 '22 03:12

JY2k


1 Answers

I was missing:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name="com.orm.SugarApp" >

android:name="com.orm.SugarApp

like image 54
JY2k Avatar answered Dec 10 '22 11:12

JY2k