From 5635697223a38bc574b0a4209100c183711e4b49 Mon Sep 17 00:00:00 2001 From: houxg Date: Tue, 14 Feb 2017 11:40:20 +0800 Subject: [PATCH] fix recent notebook might be null --- .../org/houxg/leamonax/database/AppDataBase.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java b/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java index 717775d..cdea73e 100644 --- a/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java +++ b/app/src/main/java/org/houxg/leamonax/database/AppDataBase.java @@ -238,21 +238,19 @@ public class AppDataBase { } public static Notebook getRecentNoteBook(String userId) { - List recentNotes = SQLite.select() + Note recentNotes = SQLite.select() .from(Note.class) .where(Note_Table.userId.eq(userId)) .and(Note_Table.notebookId.notEq("")) .orderBy(Note_Table.updatedTime, false) - .queryList(); - - if (CollectionUtils.isNotEmpty(recentNotes)) { - for (Note note : recentNotes) { - Notebook notebook = getNotebookByServerId(note.getNoteBookId()); - if (!notebook.isDeleted()) { - return notebook; - } + .querySingle(); + if (recentNotes != null) { + Notebook notebook = getNotebookByServerId(recentNotes.getNoteBookId()); + if (notebook != null && !notebook.isDeleted()) { + return notebook; } } + return SQLite.select() .from(Notebook.class) .where(Notebook_Table.userId.eq(userId))