简体   繁体   中英

SugarORM: SugarRecord.count returns 4 but SugarRecord.listAll returns empty list

I use the @Table annotation for my model and call SugarRecord.save in a DialogFragment.setPositiveButton.onClick

In the Fragment with the ListView I wanted to load all entries via SugarRecord.listAll but it returns an empty list, although SugarRecord.count returns the proper count.

My Code

Syllable.java

@Table
@ToString
@Getter
public class Syllable {

    private Long id;

    @Unique
    String characters;
    @Setter
    boolean active = true;

    public Syllable(String characters) {
        this.characters = characters;
    }
}

DialogFragment.setPositiveButton

.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        SugarRecord.save(new Syllable(charactersET.getText().toString()));
                        syllableDialogListener.onSyllableSave();
                    }
                })

Fragment.onSyllableSave

private void updateSyllables() {
        long count = SugarRecord.count(Syllable.class); // returns 4 (e.g.)
        List<Syllable> syllables = SugarRecord.listAll(Syllable.class); // returns empty list
    }

好的,我只是在模型中缺少一个空的构造函数 >>> 问题是这在 android studio 中并没有真正打印为红色错误样式的错误,所以我只是错过了这个;D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM