// Create a JSON request
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, jsonBody,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String message = response.getString("message");
if (message.equals("Login successful")) {
Toast.makeText(Login.this, message, Toast.LENGTH_SHORT).show();
startActivity(new Intent(Login.this, MainActivity.class));
finish(); // Optional: Finish Login activity
} else {
Toast.makeText(Login.this, message, Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
Log.e("Login", "Response parsing error: " + e.getMessage());
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Login", "Volley error: " + error.getMessage());
Toast.makeText(Login.this, "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Can someone tell why does this code return an error of Cannot convert string to JsonObject?