I have simple method with AsyncTask
, but code suddenly crashed. Any ideas?
I got Could not parse malformed JSON:
, and now I get NPE at new AsyncTask<String, Void, String>() {
My code:
private void getMyPage() {
new AsyncTask<String, Void, String>() {
ProgressDialog dialog = new ProgressDialog(UserProfileActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
Create Dialog...
}
@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<>();
data.put("token", params[0]);
LoginLectorUtils apiUtils = new LoginLectorUtils();
return apiUtils.sendPostRequestWithParams(REQUEST_URL, data);
}
@Override
protected void onPostExecute(String response) {
super.onPostExecute(response);
dialog.dismiss();
if (!response.equalsIgnoreCase("error")) {
try {
final JSONObject jsonObject = new JSONObject(response);
if (jsonObject.getString("error").equals("true")) {
showDialogConnectionError();
} else if (jsonObject.getString("error").equalsIgnoreCase("false")) {
doLoadStuff(
jsonObject.getString("name"),
jsonObject.getString("phone")
}
} catch (Throwable t) {
Log.e("UserProfileActivity", "Could not parse malformed JSON: \"" + response + "\"");
}
} else {
}
}
}.execute(sharedPrefUtils.getToken());
}