Where is the error when inserting into my database from android with the help of retrofit 2.3.0?

0

Hi, I'm doing an app where I have to insert data in a database table, so far I'm just doing tests to see how retrofit works, the question is that I already make an example where I have to insert only id, name , and last name in the table, the id is autoincrement, and only the name and the last name I send it from a form, I already have defined my interface with its respective endpoint and the model class for the answer in json that only receives a status with its respective value to show it in a toast,

by pressing the registration button I get this error

I'm using SLIM 2 for the API

here is the function

$app->post('alta/:nombre/:apellidos', function($nombre,$apellidos) use ($app){
$conexion = getConnection();
$sql = "INSERT INTO tabla_comodin(nombre,apellidos) VALUES (:nombre,:apellidos)";
$consulta = $conexion->prepare($sql);
$consulta->bindParam("nombre",$nombre);
$consulta->bindparam("apellidos",$apellidos);
$consulta->execute();

if ($consulta->rowCount()!=0){
            echo '{"estatus":"Este es una prueba desde el nuevo sistema con el metodo POST"}';
    }else{
        echo '{"estatus":"NO se pudo registrar el contactos"}';
    }
$conexion = null;

});

    
asked by JesusSh 31.08.2017 в 18:24
source

2 answers

1

In your class registrar() you pass two arguments:

registrar(String nombre, String apellidos)

In the same method, if we go down, you have the line:

Call<Resultado> call = servicio.pepe(nombre, apellido);

So you are passing an incorrect argument, replace:

Call<Resultado> call = servicio.pepe(nombre, apellidos);

    
answered by 31.08.2017 в 23:23
0

You must mark the fields with the attribute @SerializeName so that the serializer can assign the value of the json.

For example, if the server response is

{ "estatus_22": "Datos guardados"}

Class resultado should have the field estatus marked as follows:

public class resultado
{

 @SerializeName("status_22")
  private String status;


  public void setStatus(String status)
  {
    this.status = status;
  }

  public String getStatus()
  {
    return this.status;
  }
}
    
answered by 31.08.2017 в 18:53