Reputation: 2909
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.
Upvotes: 4
Views: 5211
Reputation: 2909
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
Upvotes: 13
Reputation: 1532
Which version of the library are you using?
Btw, You may want to add the DOMAIN_PACKAGE_NAME configuration as well. This restricts the domain classes to a particular package. http://satyan.github.io/sugar/getting-started.html#configuration
Upvotes: 2