Realm object loosing data after I change some data

Viewed 18

So I have a simple notes app, it has a noteModel class which extends RealmObject. I added a boolean value "pinned" to it but when I set this value to true it stops returning any of the data saved to it. The title starts returning null in the adapter and I can't use it but when I set "pinned" back to false everything goes back to normal. Here is the Model class

public class NoteModel extends RealmObject {
@PrimaryKey
private int noteID;

private String note;
private String title;
private long timeStamp;
private boolean archived;
private boolean pinned;

public NoteModel() {
}

public boolean isPinned() {
    return pinned;
}

public void setPinned(boolean pinned) {
    this.pinned = pinned;
}

public int getNoteID() {
    return noteID;
}

public void setNoteID(int noteID) {
    this.noteID = noteID;
}

public String getNote() {
    return note;
}

public void setNote(String note) {
    this.note = note;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public long getTimeStamp() {
    return timeStamp;
}

public void setTimeStamp(long timeStamp) {
    this.timeStamp = timeStamp;
}

public boolean isArchived() {
    return archived;
}

public void setArchived(boolean archived) {
    this.archived = archived;
}

}

Here is the adapter code:

switch (which) {
                        case 0:
                            if (noteModel.isPinned()) {
                                realm.beginTransaction();
                                noteModel.setPinned(false);
                                realm.commitTransaction();

                                Prevalent.allNotes.add(noteModel);
                                Prevalent.pinnedNotes.remove(pos);
                            } else {
                                realm.beginTransaction();
                                noteModel.setPinned(true);
                                realm.commitTransaction();

                                Prevalent.pinnedNotes.add(noteModel);
                                Prevalent.allNotes.remove(index);
                            }
                            notifyItemRemoved(index);
                            NotesFragment.pinNote();
                            break;

}

When it looses the data it just starts returning null for every get request apart from pinned

0 Answers
Related