首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SugarORM -“listall”返回空列表

SugarORM -“listall”返回空列表
EN

Stack Overflow用户
提问于 2015-11-09 13:35:02
回答 1查看 596关注 0票数 1

我有这门课:

代码语言:javascript
复制
public class ProfileData extends SugarRecord {
@Expose
public Data data;

public ProfileData(Data data) {
    this.data = data;
}

public static class Data {
    public long id;
    @Expose
    public String email;
    @Expose
    public String name;
    @Expose
    public String surname;
    @Expose
    public String address;
    @Expose
    public String city;
    @Expose
    public long pesel;
    @Expose
    public long phone;
    @Expose
    public long userId;
    @Expose
    public long clubId;
    @Expose
    public String fullName;
    @Expose
    public long clientStatusId;
    @Expose
    public String provider;
    @Expose
    public String uid;
    @Expose
    public boolean gender;


    public Data(long id, String email, String name, String surname, String address, String city,
                long pesel, long phone, long userId, long clubId, String fullName,
                long clientStatusId, String provider, String uid, boolean gender) {
        this.id = id;
        this.email = email;
        this.name = name;
        this.surname = surname;
        this.address = address;
        this.city = city;
        this.pesel = pesel;
        this.phone = phone;
        this.userId = userId;
        this.clubId = clubId;
        this.fullName = fullName;
        this.clientStatusId = clientStatusId;
        this.provider = provider;
        this.uid = uid;
        this.gender = gender;
    }
}

我用来自JSON的数据填充这个类(用Gson)。然后调用save()方法('data‘对象是ProfileData的一个实例):

代码语言:javascript
复制
data.save();

我的下一步是:

代码语言:javascript
复制
List<ProfileData> profileList = ProfileData.listAll(ProfileData.class);

和profileList是空的。

我将这一行放入AndroidManifest中:

代码语言:javascript
复制
<meta-data
        android:name="DATABASE"
        android:value="sugar_example_my.db" />
    <meta-data
        android:name="VERSION"
        android:value="2" />
    <meta-data
        android:name="QUERY_LOG"
        android:value="true" />
    <meta-data
        android:name="DOMAIN_PACKAGE_NAME"
        android:value="com.example.my" />

最后,在我的App类中,我写了一行:

代码语言:javascript
复制
SugarContext.init(this);

有什么建议吗?

编辑:

通过向数据类中添加公共数据() {}并移动

扩展SugarRecord

从ProfileData到数据。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-09 13:43:14

我想麻烦的是你的名单应该是List<Data>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33610319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档