getting this error in my app
W/System.err: org.json.JSONException: Value br of type java.lang.String cannot be converted to JSONObject
this is my RegisterActivity.java
public class RegisterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
final EditText etName=(EditText) findViewById(R.id.etname);
final EditText etUsername=(EditText) findViewById(R.id.etusername);
final EditText etPassword=(EditText) findViewById(R.id.etpassword);
final EditText etCPassword=(EditText) findViewById(R.id.etcpassword);
final EditText etEmail=(EditText) findViewById(R.id.etemail);
final EditText etContact=(EditText) findViewById(R.id.etcontact);
final EditText etAge=(EditText) findViewById(R.id.etage);
final Button btnRegister=(Button) findViewById(R.id.btnregister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name=etName.getText().toString();
final String username=etUsername.getText().toString();
final String password=etPassword.getText().toString();
final String email=etEmail.getText().toString();
final int age=Integer.parseInt(etAge.getText().toString());
final int contact=Integer.parseInt(etContact.getText().toString());
Response.Listener<String> responseListener = new Response.Listener<String>(){
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse= new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if(success){
Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
RegisterActivity.this.startActivity(intent);
}else{
AlertDialog.Builder builder= new AlertDialog.Builder(RegisterActivity.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry",null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
AlertDialog.Builder build= new AlertDialog.Builder(RegisterActivity.this);
build.setMessage("JSON Failed")
.setNegativeButton("Retry",null)
.create()
.show();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(name,username,password,email,contact,age,responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
}
});
}
}
this is RegistryRequest.java
public class RegisterRequest extends StringRequest{
private static final String REGISTER_REQUEST_URL="https://smplycode.000webhostapp.com/Registerft.php";
private Map<String, String> params;
public RegisterRequest(String name,String username,String password,String email,int contact, int age, Response.Listener<String> listener) {
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("name",name);
params.put("username",username);
params.put("password",password);
params.put("email",email);
params.put("contact",contact+"");
params.put("age",age+"");
}
@Override
public Map<String, String> getParams() {return params;}
}
this is my registerft.php file
<?php
$con = mysqli_connect("localhost", "id20401_mydbname", "mydbpaord", "id2041_mydme");
$name = $_POST["name"];
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$contact = $_POST["contact"];
$age = $_POST["age"];
$statement = mysqli_prepare($con, "INSERT INTO usersft (name, username, password, email, contact, age) VALUES (?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "ssssii", $name, $username,$password,$email,$contact, $age);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
i watched this tutorial on youtube this code working on that tutorial.
Getting this when printing response string as an alert
if anyone want to help please give me your email id i am doing project i want to make an app on c++ learning for new comers :)