Null Pointer Exception

  • Replies:3
  • OpenNot stickiedUnanswered
  • Forum posts: 11

Apr 15, 2017 11:48:13 AM via Website

i have faced pblm when i clicked on login button on login activity.this is my debug logact:
04-15 15:07:45.924 2533-2533/volleyjson.androidhive.info.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: volleyjson.androidhive.info.myapplication, PID: 2533
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.app.ProgressDialog.isShowing()' on a null object reference
at volleyjson.androidhive.info.myapplication.login.showProgressDialog(login.java:55)
at volleyjson.androidhive.info.myapplication.login.makeJsonObjReq(login.java:64)
this is my login activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_dialogue);
t1 = (TextView) findViewById(R.id.textView1);
t2 = (TextView) findViewById(R.id.textView2);
t3 = (TextView) findViewById(R.id.textView3);
ed1 = (EditText) findViewById(R.id.RegEmail);
b1 = (Button) findViewById(R.id.btnLogin);
b1.setOnClickListener(this);
ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
}
private void showProgressDialog() {
if (!pDialog.isShowing())
pDialog.show();
}

private void hideProgressDialog() {
    if (pDialog.isShowing())
        pDialog.hide();
}
private void makeJsonObjReq() {
    showProgressDialog();
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
            LOGIN_URL , null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                    openProfile();
                    pDialog.hide();
                }
            }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            hideProgressDialog();
        }
    }) {

        /**
         * Passing some request headers
         * */
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("Content-Type", "application/json");
            return headers;
        }
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put(KEY_EMAIL, email);

            return params;
        }

    };

    // Adding request to request queue
    String tag_json_obj = "jsonObjReq ";
    AppController.getInstance().addToRequestQueue(jsonObjReq,
            tag_json_obj);

    // Cancelling request
    // ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_obj);
}
private void openProfile(){
    Intent intent = new Intent(login.this, MainActivity.class);
    intent.putExtra(KEY_EMAIL,email);
    startActivity(intent);
}

@Override
public void onClick(View v) {

    makeJsonObjReq();
}

}

                                                                                         at volleyjson.androidhive.info.myapplication.login.onClick(login.java:120)
                                                                                         at android.view.View.performClick(View.java:5637)
                                                                                         at android.view.View$PerformClick.run(View.java:22429)
                                                                                         at android.os.Handler.handleCallback(Handler.java:751)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

— modified on Apr 15, 2017 11:49:35 AM

  • Forum posts: 11

Apr 17, 2017 8:20:45 AM via Website

again i got this error
04-17 11:38:16.471 2362-2362/volleyjson.androidhive.info.myapplication W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
04-17 11:38:39.920 2362-3293/volleyjson.androidhive.info.myapplication D/NetworkSecurityConfig: No Network Security Config specified, using platform default
04-17 11:38:41.270 2362-3293/volleyjson.androidhive.info.myapplication E/Volley: [93] BasicNetwork.performRequest: Unexpected response code 404 fo nishkarsh.co.in/api/login
04-17 11:38:41.271 2362-2362/volleyjson.androidhive.info.myapplication D/Volley: [1] 2.onErrorResponse: login
please help to rectify it.my login activity is given above

  • Forum posts: 11

Apr 17, 2017 9:15:08 AM via Website

and when click on API link then in brawser it shows GET method not acceptable