我在Volley请求中的响应始终进入错误监听器

时间:2018-06-25 10:11:45

标签: android json android-volley response

我正在使用volly进行json响应,这是我的java代码,我尝试了所有操作,但找不到错误。它总是转到错误侦听器。我真的不知道为什么我的响应会转到错误侦听器,任何机构帮助我,请先谢谢

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

}

这是我在php中的json响应

{"value":"Record Inserted Successfully"}

1 个答案:

答案 0 :(得分:2)

问题是未指定URL协议

void paint(Canvas canvas, Size size) {
int c = 0;
canvas.save();
canvas.translate(size.width / 2, size.height / 2);
canvas.rotate(-rotation);

for (var i = 0; i < 16; ++i) {
  if (i % 2 == 0) {
    canvas.drawLine(
      new Offset(0.0, 0.0),
      new Offset(0.0, size.width / 2 - 4.2),
      tickPaint,
    );
  } else {
    canvas.save();
    canvas.translate(-0.0, -((size.width) / 2));
    canvas.clipPath(path);
    if (images[c] != null) {
      ui.Image img = images[c];
      canvas.drawImage(img, Offset(0.0, 0.0), new Paint());
    }
    canvas.rotate(2 * pi);
    canvas.restore();
    c++;
  }
  canvas.rotate(2 * pi / 16);
}
canvas.restore();}

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