Volley library NetworkDispatcher.run error

Viewed 12737

In my program there is NetworkDispatcher.run error I am using volley library. my program part is .I done all the way but nothing worked please helpme to do my program.I searced through many web content but nothing helped me.I am doing is a Login verification program in android.

if(!(usr.getText().toString().length()<11)&&!(pwd.getText().toString().length()<3)) {
                    susr = usr.getText().toString();
                    spwd = pwd.getText().toString();
                    String whois = susr.substring(0, Math.min(susr.length(), 2));
                    if (whois.equals("AG") || whois.equals("RT")) {
                        if (whois.equals("AG")) {

                            id = susr.substring(susr.length() - 9);
                            Toast.makeText(getApplicationContext(), id, Toast.LENGTH_LONG).show();
                            StringRequest stringRequest = new StringRequest(Request.Method.POST, agenturl,
                                    new Response.Listener<String>() {
                                        @Override
                                        public void onResponse(String response) {
                                            //Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
                                            if(response.equals("0")){
                                                Toast.makeText(getApplicationContext(),"Login successful",Toast.LENGTH_LONG).show();
                                                Intent intent=new Intent(getBaseContext(),Deals.class);
                                                startActivity(intent);
                                            }else{
                                                Toast.makeText(getApplicationContext(),"username or password is incorrect",Toast.LENGTH_LONG).show();
                                            }
                                        }
                                    },
                                    new Response.ErrorListener() {
                                        @Override
                                        public void onErrorResponse(VolleyError error) {
                                            //Toast.makeText(MainActivity.this,error.toString(), Toast.LENGTH_LONG).show();
                                            if(error instanceof NoConnectionError) {
                                                Toast.makeText(getApplicationContext(),"No internet Access, Check your internet connection.", Toast.LENGTH_LONG).show();
                                            }
                                        }
                                    }){
                                @Override
                                protected Map<String,String> getParams(){
                                    Map<String,String> params = new HashMap<String, String>();
                                    params.put("id",id);
                                    params.put("pwd",spwd);
                                    return params;
                                }

                            };
                            requestQueue.add(stringRequest);
                        }
                        else if(whois.equals("RT")){

                            StringRequest stringRequest2 = new StringRequest(Request.Method.POST, retailerurl,
                                    new Response.Listener<String>() {
                                        @Override
                                        public void onResponse(String response) {
                                            //Toast.makeText(getApplicationContext(),"hf",Toast.LENGTH_LONG).show();
                                            //Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
                                            if(response.equals("0")){
                                                Toast.makeText(getApplicationContext(),"Login successful",Toast.LENGTH_LONG).show();
                                                Intent intent=new Intent(getBaseContext(),Deals.class);
                                                startActivity(intent);
                                            }else{
                                                Toast.makeText(getApplicationContext(),"username or password is incorrect",Toast.LENGTH_LONG).show();
                                            }
                                        }
                                    },
                                    new Response.ErrorListener() {
                                        @Override
                                        public void onErrorResponse(VolleyError error) {
                                            //Toast.makeText(MainActivity.this,error.toString(), Toast.LENGTH_LONG).show();
                                            if(error instanceof NoConnectionError) {
                                                Toast.makeText(getApplicationContext(),"No internet Access, Check your internet connection.", Toast.LENGTH_LONG).show();
                                            }
                                        }
                                    }){
                                @Override
                                protected Map<String,String> getParams(){
                                    Map<String,String> params = new HashMap<String, String>();
                                    params.put("id",id);
                                    params.put("pwd",spwd);
                                    return params;
                                }

                            };
                            requestQueue2.add(stringRequest2);
                        }
                    } else{
                        Toast.makeText(getApplicationContext(), "The user id or password is incorrect", Toast.LENGTH_LONG).show();
                        usr.setText("");
                    }
                }else {
                    Toast.makeText(getApplicationContext(), "The user id or password is incorrect", Toast.LENGTH_LONG).show();
                    usr.setText("");
                }

and the error log cat is.

E/Volley: [197] NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
                                                               at libcore.net.UriCodec.encode(UriCodec.java:132)
                                                               at java.net.URLEncoder.encode(URLEncoder.java:57)
                                                               at com.android.volley.Request.encodeParameters(Request.java:484)
                                                               at com.android.volley.Request.getBody(Request.java:470)
                                                               at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:253)
                                                               at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:227)
                                                               at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:107)
                                                               at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)
                                                               at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
3 Answers
Related