我为什么会收到此“ E / org.json.JSONException:输入字符结束于0的字符:onErrorResponse:”错误?

时间:2019-08-15 13:56:30

标签: java android json jsonexception

我正在使用排球库从android设备向春季后端发送一个后发请求到服务器。此发布请求用于注册新用户。一切正常,按预期将发布请求发送到服务器,服务器接受请求,并在数据库上创建新用户。但是没有让用户成功创建烤面包,而是在我的Android应用中创建用户时出错。

我找不到代码所累。

这是我在android上的代码:

// sends data to the server
public void createNewUser(){

    final String BASE_URL = BaseUrl.BASE_URL_CUSTOMER;
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    // sending the json file to the server
    JSONObject postParams = new JSONObject();
    try {
        postParams.put("firstName", customer.getFirstName());
        postParams.put("lastName",customer.getLastName());
        postParams.put("email",customer.getEmail());
        postParams.put("password",customer.getPassword());
        Log.e("testing", "createNewUser: "+postParams.toString());
    }catch (Exception e){
        Log.d(e.getMessage(), "createNewUser: error while creating a new user");
    }

   JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BASE_URL, postParams, new Response.Listener<JSONObject>() {
       @Override
       public void onResponse(JSONObject response) {
           Log.e(response.toString(), "onResponse: " );
           Toast.makeText(getApplicationContext(),"Creating new user",Toast.LENGTH_SHORT).show();
       }
   }, new Response.ErrorListener() {
       @Override
       public void onErrorResponse(VolleyError error) {
           Toast.makeText(getApplicationContext(),"Error:Creating new user",Toast.LENGTH_SHORT).show();
           Log.e(error.getMessage(), "onErrorResponse:");
       }


   });
    requestQueue.add(jsonObjectRequest);

}

我检查了邮递员,我的答复如下:

{
"firstName": "xyz",
"lastName": "abc",
"email": "xyzabc@gmail.com",
"password": "12345678",
"_links": {
"self": {
  "href": "http://localhost:8080/api/customers/22"
},
"customer": {
  "href": "http://localhost:8080/api/customers/22"
}
}
}

这是我的全部错误:

com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of 
    at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:73)
    at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
    at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
 Caused by: org.json.JSONException: End of input at character 0 of 
    at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
    at org.json.JSONTokener.nextValue(JSONTokener.java:97)
    at org.json.JSONObject.<init>(JSONObject.java:159)
    at org.json.JSONObject.<init>(JSONObject.java:176)
    at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:68)

0 个答案:

没有答案