Search code examples
androidjsonandroid-volleyresponse

My response in Volley request always get into Error Listener


i am using volly for json response this is my java code i tried every thing but unable to find error in it. it always go to Error Listener.i really dont know why my response goes to error listener any body help me please thanks in advance

private void userLoign() {
    name = Name_Et.getText().toString();
    email = Email_Et.getText().toString();
    password = Password_Et.getText().toString();
    Toast.makeText(MainActivity.this, "enter in userlogin", Toast.LENGTH_SHORT).show();

    RequestQueue queue = Volley.newRequestQueue(getApplicationContext());

   String URL = "added-platters.000webhostapp.com/application/index.php";

    Toast.makeText(MainActivity.this, "enter in Volley", Toast.LENGTH_SHORT).show();

    StringRequest myReq = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                JSONObject jObj = new JSONObject(response);
                int success = jObj.getInt("value");
                Log.e("value in success", String.valueOf(success));

                Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();

            } catch (JSONException e) {

                Log.i("myTag", e.toString());
                Toast.makeText(MainActivity.this, "Parsing error", Toast.LENGTH_SHORT).show();

            }

        }

    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.i("myTag", error.toString());

                    Toast.makeText(MainActivity.this, "Server Error", Toast.LENGTH_SHORT).show();
                }
            }) {

        @Override
        protected Map<String, String> getParams() {
            // Posting params to register url
            Map<String, String> params = new HashMap<String, String>();

            params.put("tag", "Register");
            params.put("name", name);
            params.put("email", email);
            params.put("password", password);
            params.put("lat", "1234");
            params.put("log", "1234");

            return params;
        }
    };
    myReq.setRetryPolicy(new DefaultRetryPolicy(
            20000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
    ));
    myReq.setShouldCache(false);
    queue.add(myReq);

}

and this is my json response in php

{"value":"Record Inserted Successfully"}

Solution

  • The Problem is URL Protocol not specified

    String URL = "added-platters.000webhostapp.com/application/index.php";
    

    to

    String URL = "http://added-platters.000webhostapp.com/application/index.php";