Sugar ORM listAll() not showing any data
Asked Answered
C

1

8

I'm trying to get data from databse in a listview as shown below.

  long count = UserTableSugar.count(UserTableSugar.class);
    if(count>0)
    {
        UserTableSugar.listAll(UserTableSugar.class);
        List<UserTableSugar> userTable = UserTableSugar.listAll(UserTableSugar.class);
        CustomAdapterListview madapter = new CustomAdapterListview(getApplicationContext(),userTable);
        listView.setAdapter(madapter);
    }

but,the data won't show up. On debugging, the value of count is 2 (there are two records in table). But the size of list userTable is shown 0.

SOLVED : Adding empty constructor of the model class did the trick.

Coze answered 15/6, 2016 at 11:8 Comment(4)
love u bro :* .....Dorinedorion
Possible duplicate of SugarORM: SugarRecord.count returns 4 but SugarRecord.listAll returns empty listOwain
You should post the "SOLVED" as an answer...Volvox
Why really?If it knows the count how can't it return it without empty constructorRosaleerosaleen
S
2

With SugarORM, all model classes need an empty constructor or they cannot be used.

UserTableSugar() {} will do the job!

Seedtime answered 15/6, 2016 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.