Sugar ORM how to get value

1.1k Views Asked by At

I apologize for my English, I use Google translator. The question is: how can I get the value of a particular column of a particular row. As an example - there are two columns "cost" and the "margin" in the database options scored 10 lines, how can I get a "cost" in line 5?

When I do so -

SaveData item = SaveData.findById(SaveData.class, 5);
Log.d(LOG_TAG, String.valueOf(item.cost));

then I crash

1

There are 1 best solutions below

0
On

It is the correct way to retrieve objects providing their identifier. However the "5" represents the object of type SaveData which the identifier is equal to 5, and not the #5 row.

So, check which is the identifier of the object you want to retrieve, or alternatively, get all the objects stored in the database and the select the #5 row as follows (the code is to be considered as a sample, check it before to try)

List<SaveData> list = SaveData.listAll(SaveData.class);
if (list.size() > 4) { // it means that there are at lease 5 elements
   return list.get(4);  //it retrieves the #5 element of the list/database

}