Java Android Volley 错误:com.android.volley.ClientError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53504611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Volley Error: com.android.volley.ClientError
提问by DCLXVI
I would like to know how I can rectify this issue. Research and replacement of code has been done however the problem persists.
我想知道如何解决这个问题。已经完成了代码的研究和替换,但问题仍然存在。
This is my first post on stackoverflowso excuse me if it is not in the format you expect on your usual posts.
这是我关于堆栈溢出的第一篇文章,所以如果它不是您在通常的文章中期望的格式,请原谅我。
Here is my code working with volley.
这是我使用截击的代码。
private void Regist(){
loading.setVisibility(View.VISIBLE);
btn_regist.setVisibility(View.GONE);
final String name = this.name.getText().toString().trim();
final String email = this.email.getText().toString().trim();
final String password = this.password.getText().toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try{
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
if(success.equals("1")) {
Toast.makeText(RegisterActivity.this, "Register Success!", Toast.LENGTH_SHORT).show();
}
}catch (JSONException e) {
e.printStackTrace();
Toast.makeText(RegisterActivity.this, "Register Error!" + e.toString(), Toast.LENGTH_SHORT).show();
loading.setVisibility(View.GONE);
btn_regist.setVisibility(View.VISIBLE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegisterActivity.this, "Register Error!" + error.toString(), Toast.LENGTH_SHORT).show();
loading.setVisibility(View.GONE);
btn_regist.setVisibility(View.VISIBLE);
}
})
{
@Override
protected Map<String, String> getParams()throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("name", name);
params.put("email", email);
params.put("password", password);
return super.getParams();
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
Since I receive 'com.android.volley.ClientError' I assume this is wrong but if you require the rest of the code please comment!
由于我收到“com.android.volley.ClientError”,我认为这是错误的,但如果您需要其余代码,请发表评论!
采纳答案by j3App
Replace
代替
return super.getParams()
By
经过
return params;