From b63cef8c1b4fe32015174d90f4f6b832e85fba69 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Tue, 29 Aug 2017 20:41:06 -0600 Subject: [PATCH] Fixed some more NullPointerException errors --- .../presentation/MarkdownPresenterImpl.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java index 36dac00..eef2c46 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java @@ -43,11 +43,13 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { public void loadMarkdown(String filePath) { Runnable fileLoader = () -> { int result = file.load(filePath); - if (result == MarkdownFile.SUCCESS) { - editView.setMarkdown(getMarkdown()); - onMarkdownEdited(); - } else { - editView.showFileLoadeddError(result); + if (editView != null) { + if (result == MarkdownFile.SUCCESS) { + editView.setMarkdown(getMarkdown()); + onMarkdownEdited(); + } else { + editView.showFileLoadeddError(result); + } } }; fileLoader.run(); @@ -62,7 +64,8 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { editView.setMarkdown(getMarkdown()); onMarkdownEdited(); } else { - editView.showFileLoadeddError(result); + if (editView != null) + editView.showFileLoadeddError(result); } }; fileLoader.run(); @@ -99,10 +102,12 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { Runnable fileSaver = () -> { int code; code = file.save(filePath); - if (code == MarkdownFile.SUCCESS) { - editView.showFileSavedMessage(); - } else { - editView.showFileSavedError(code); + if (editView != null) { + if (code == MarkdownFile.SUCCESS) { + editView.showFileSavedMessage(); + } else { + editView.showFileSavedError(code); + } } }; fileSaver.run(); @@ -173,7 +178,8 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { } loadMarkdown(in); } catch (Exception e) { - editView.showFileLoadeddError(MarkdownFile.READ_ERROR); + if (editView != null) + editView.showFileLoadeddError(MarkdownFile.READ_ERROR); } } }