Hi, I am working with retrofit 2.3.0 and slim v2, and when sending the data by means of retrofit, the json that has to be received is not returned and it may not even send the data of the form, since another function of the api if it works for me
endpoints file (interface retrofit)
public interface apiAdapter {
@POST("login/{usuario}/{password}/{googleId}/{idDispositivo}")
Call<resultado> login(@Path("usuario") String usuario,@Path("password") String password,@Path("googleId") String googleId,@Path("idDispositivo") String idDispositivo);
@POST("guardarForm/{ubicacion}/{contrato}/{inicial}/{final}/{total}/{bobina}/{usuario}/{servicio}/{orden}")
Call<resultado> guardarServicioForm (@Path("ubicacion") String ubicacion,@Path("contrato") String contrato,@Path("inicial") String inicial,@Path("final") String finl,@Path("total") int total,@Path("bobina") String bobina,@Path("usuario") int usuario, @Path("servicio") int servicio,@Path("orden") int orden);
@GET("login2")
Call<resultado> mensaje();
}
this the file that manages the json that receives
public class resultado {
@SerializedName("estatus")
@Expose
private String estatus;
public String getEstatus() {
return estatus;
}
public void setEstatus(String estatus) {
this.estatus = estatus;
}
}
and the following code is the part of the function where I click to send the form
Retrofit retrofit2 = new ApiConfigRetrofit().consultas();
apiAdapter servicio = retrofit2.create(apiAdapter.class);
//persona pepe = new persona(email,password,"dfgf","dfgfd");
Call<resultado> llamada = servicio.login("sdfs","password","fdgf","dfdgf");
llamada.enqueue(new Callback<resultado>() {
@Override
public void onResponse(Call<resultado> call, Response<resultado> response) {
Toast.makeText(getApplicationContext(),response.body().getEstatus(),Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<resultado> call, Throwable t) {
Toast.makeText(getApplicationContext(),t.toString(),Toast.LENGTH_SHORT).show();
}
});
and this is the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: appstda.erp.com.mx.siga40, PID: 10401
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String pruebasEjemplos.resultado.getEstatus()' on a null object reference
at LoginActivity$4.onResponse(LoginActivity.java:237)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)