0

I'm using the android Volley to connect to server.The stringRequest POST is used to do the same

        StringRequest strReq = new StringRequest(Method.POST,
                AppConfig.URL_LOGIN, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d(TAG, "Login Response: " + response.toString());
                hideDialog();

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Login Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_LONG).show();
                hideDialog();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                // Posting parameters to login url
                Map<String, String> params = new HashMap<String, String>();
                params.put("email", email);
                params.put("password", password);
                Log.e(TAG,email+password);
                return params;
            }

        };
        // Adding request to request queue

        AppController.getInstance().addToRequestQueue(strReq,tag_string_req);
    }

But it shows the following logcat error when I click the button

FATAL EXCEPTION: main Process: com.baellife.test.baellife, PID: 5285                                                                              java.lang.NullPointerException: Attempt to invoke virtual method 'void com.baellife.test.baellife.AppController.addToRequestQueue(com.android.volley.Request, java.lang.String)' on a null object reference
                                                                              at com.baellife.test.baellife.LoginActivity.checkLogin(LoginActivity.java:185)                                                                                 at com.baellife.test.baellife.LoginActivity.access$200(LoginActivity.java:32)                                                                                at com.baellife.test.baellife.LoginActivity$1.onClick(LoginActivity.java:80)                                                                                 at android.view.View.performClick(View.java:5204)                                                                                  at android.view.View$PerformClick.run(View.java:21153)                                                                                 at android.os.Handler.handleCallback(Handler.java:739)                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)                                                                                  at android.os.Looper.loop(Looper.java:148)                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

It seems strReq in

AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

is returning NULL.

0 Answers0