From c213cc0962c13cd8450ea1be89775c40dc7f7f15 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 2 Dec 2020 15:20:29 +0800 Subject: Fix some NullPointerException. --- .../subreddit/SubredditListingDataSource.java | 2 +- .../infinityforreddit/user/ParseUserData.java | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'app/src/main/java/ml/docilealligator') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java index 3757cde9..a9dad4b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java @@ -83,7 +83,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource { private JSONObject jsonResponse; private ParseUserDataListener parseUserDataListener; - private boolean parseFailed; + private boolean parseFailed = false; private UserData userData; ParseUserDataAsyncTask(String response, ParseUserDataListener parseUserDataListener) { + this.parseUserDataListener = parseUserDataListener; try { jsonResponse = new JSONObject(response); - this.parseUserDataListener = parseUserDataListener; - parseFailed = false; } catch (JSONException e) { + parseFailed = true; e.printStackTrace(); - parseUserDataListener.onParseUserDataFailed(); } } @Override protected Void doInBackground(Void... voids) { - try { - userData = parseUserDataBase(jsonResponse, true); - } catch (JSONException e) { - parseFailed = true; - e.printStackTrace(); + if (!parseFailed) { + try { + userData = parseUserDataBase(jsonResponse, true); + } catch (JSONException e) { + parseFailed = true; + e.printStackTrace(); + } } return null; } -- cgit v1.2.3