From 5e4e1692e6b6429d330703012d73681ea92579e7 Mon Sep 17 00:00:00 2001 From: esensar Date: Sat, 7 Jan 2017 17:25:52 +0100 Subject: [PATCH] Fix for when there is no user in cache --- .../com/smarthomies/realtimetalk/database/UserDAO.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/smarthomies/realtimetalk/database/UserDAO.java b/app/src/main/java/com/smarthomies/realtimetalk/database/UserDAO.java index 0626d76..3a01aff 100644 --- a/app/src/main/java/com/smarthomies/realtimetalk/database/UserDAO.java +++ b/app/src/main/java/com/smarthomies/realtimetalk/database/UserDAO.java @@ -15,7 +15,12 @@ public class UserDAO extends RealmDAO { } public User findUserById(Realm realm, int id) { - return realm.copyFromRealm(realm.where(entityClass).equalTo(User.PRIMARY_KEY, id).findFirst()); + User user = realm.where(entityClass).equalTo(User.PRIMARY_KEY, id).findFirst(); + if(user != null) { + return realm.copyFromRealm(user); + } else { + return null; + } } public void deleteById(Realm realm, int id) {