0

I'm facing an error on my Android app, which throw a JSONException everytime I run it.

This is my PHP code, which simply return true if every value of type in my table is equals to 'run':

$userId = $_POST["userId"]; 
$statement = mysqli_prepare($con, "SELECT type FROM performance WHERE userId = ?");
mysqli_stmt_bind_param($statement, "i", $userId);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement,  $type);
$correct = false;  
while(mysqli_stmt_fetch($statement)){
    if(strcmp($type,"run")==0)     $correct = true;
    else     $correct = false;
}
mysql_close($statement);
echo json_encode($correct);

And this is my Android code, I'm using the Volley library:

Response.Listener<String> responseListener = new Response.Listener<String>(){
    @Override
    public void onResponse(String response) {
        try {
            JSONObject jsonResponse = new JSONObject(response);
            boolean success = jsonResponse.getBoolean("correct");
            if (success)
                /*do something*/
            else
                /*do something else*/
        }catch (JSONException e) {
            e.printStackTrace();
        }    
    }    

But, everytime I run my app is called the JSONException, it says

org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

Can anyone help me?

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28

0 Answers0