Fix some NullPointerException.

This commit is contained in:
Alex Ning 2020-12-02 15:20:29 +08:00
parent 5c31c21d06
commit c213cc0962
2 changed files with 11 additions and 10 deletions

View File

@ -83,7 +83,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
this.params = params;
this.callback = callback;
if (params.key.equals("") || params.key.equals("null")) {
if (params.key == null || params.key.equals("") || params.key.equals("null")) {
return;
}

View File

@ -70,28 +70,29 @@ public class ParseUserData {
private static class ParseUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
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;
}