创建AsyncTask时出现NullPointerException

时间:2016-02-04 15:16:26

标签: java android android-asynctask nullpointerexception

我有AsyncTask的简单方法,但代码突然崩溃了。有任何想法吗? 我得到了Could not parse malformed JSON:,现在我在new AsyncTask<String, Void, String>() {获得了NPE 我的代码:

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());
    }

0 个答案:

没有答案