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

廉价感情. 提交于 2019-12-12 19:14:33

问题


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
    }

回答1:


OK, I was just missing an empty constructor at the model >_> Problem was this wasn't really printed as an red-error-style error in android studio so I just missed this ;D



来源:https://stackoverflow.com/questions/37521271/sugarorm-sugarrecord-count-returns-4-but-sugarrecord-listall-returns-empty-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!