0
I have the following method to send an object to my api:
public void btnCadastrar(View view) throws JSONException, IOException {
final EditText edtNome = ((EditText) findViewById(R.id.edtNome));
final EditText edtSobrenome = ((EditText) findViewById(R.id.edtSobrenome));
EditText edtCelular = ((EditText) findViewById(R.id.edtCelular));
EditText edtCep = ((EditText) findViewById(R.id.edtCep));
EditText edtLogradouro = ((EditText) findViewById(R.id.edtLogradouro));
EditText edtBairro = ((EditText) findViewById(R.id.edtBairro));
EditText edtLocalidade = ((EditText) findViewById(R.id.edtCidade));
EditText edtUF = ((EditText) findViewById(R.id.edtUF));
String nome = edtNome.getText().toString();
String sobrenome = edtSobrenome.getText().toString();
String celular = edtCelular.getText().toString();
String cep = edtCep.getText().toString();
String logradouro = edtLogradouro.getText().toString();
String bairro = edtBairro.getText().toString();
String cidade = edtLocalidade.getText().toString();
String uf = edtUF.getText().toString();
JSONObject dadosJsonObject = new JSONObject();
dadosJsonObject.put("nome", edtNome.getText().toString());
dadosJsonObject.put("sobrenome", edtSobrenome.getText().toString());
dadosJsonObject.put("celular", edtCelular.getText().toString());
dadosJsonObject.put("cep", edtCep.getText().toString());
dadosJsonObject.put("logradouro", edtLogradouro.getText().toString());
dadosJsonObject.put("bairro", edtBairro.getText().toString());
dadosJsonObject.put("cidade", edtLocalidade.getText().toString());
dadosJsonObject.put("uf", edtUF.getText().toString());
dadosJsonObject.toString();
JsonObjectRequest json = new JsonObjectRequest(Request.Method.PATCH,
"http://reservacomdomanda.com/areaAdmin/api/admin_estabelecimento/usuarios.php", dadosJsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//Toast.makeText(getBaseContext(),"Dados retornados: "+response, Toast.LENGTH_LONG).show();
finish();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(CadastroActivity.this, "Tente novamente", Toast.LENGTH_SHORT).show();
}
}
);
mVolleyRequest.add(json);
}
}
And this is my API:
<?php
header("Access-Control-Allow-Origin: *");
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("con.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($dadosJsonObject);
var_dump($data);
?>
When I click the button to send the object to the api, a message appears on the emulator screen saying that the application has stopped and I can’t find the error.
Could you add the error log ? becomes easier to help!
– Thiago Luiz Domacoski
You know how to debug the code?
– viana
Oh that’s, no error log.. At least no error appears. How can I put this log and where?
– GustavoSevero
How and where can I put the log @Thiagoluizdomacoki
– GustavoSevero
I found the error: "Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'com.android.Volley.Request com.android.Volley.RequestQue.add(com.android.Volley.Request)' on a null Object Reference at.example.Gustavo.domanda.Cadasactivity.btnCast"
– GustavoSevero