I am sending a post request to the server using volley library from android device to the spring backend. This post request is for registering the new user. Every thing works fine as intended the post request is sent to server the server accepts the request and new user is created on the database. but instead of getting user created sucessfully toast i get error creating user in my android app.
I can't find what is worng with the code.
this is my code on 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);
}
i check on post man and my response looks like this:
{
"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"
}
}
}
this is my full error:
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)