Reputation: 8494
I'm trying to figure out how to use sugarORM (version 1.4, imported with Gradle).
I have a simple object with a public String name
field, among others.
I construct that simple object with that name and save it like this (with TEST_TYPE
a random String) :
CustomObject type = new CustomObject(TEST_TYPE);
long l=type.save();
Toast.makeText(this, "Type ajouté ! id="+l, Toast.LENGTH_SHORT).show();
My log is showing id=14 by now, so I assume writing is OK.
But when I want to read, there is no sense :
CustomObject.count(CustomObject.class)
returns 14CustomObject.findById(CustomObject.class, 2)
returns nullCustomObject.first(CustomObject.class)
returns nullCustomObject.find(LifeEventType.class, "NAME = ?", new String[]{TEST_TYPE})
returns nullI don't know if it is related, but I get this exception on warning log :
java.lang.NoSuchMethodException: <init> at com.orm.SugarRecord.find(SugarRecord.java:196)
(which is code too advanced for a noob like me...)
What am I doing wrong ?
Upvotes: 3
Views: 1425
Reputation: 519
It happens when you don't provide an empty contructor.
SugarORM can correctly save the entities, but can't instantiate them when you try to perform a select query.
The solution is to include an empty constructor and the getters/setters within your entity
public CustomObject(){}
More documentation here
Upvotes: 19