0

I have to make a call sending a json to an api using retrofit 1.9, that call I will get a response with weather info in Json. To implement it I have followed this stackoverflow question

this is the json I have to sent:

{jsondata:{"when":1,"city":2 }}

this is my interface:

    public interface ApiCalls {

    @POST("/getConditions.php")
    void getConditions(@Body JsonAdded json, Callback <List<PojoBeaches>> response);

}

The classes I have created for the (@body JsonAdded json, ..) parameter

> public class Jsondata {

    @SerializedName("when")
    @Expose
    private Integer when;
    @SerializedName("city")
    @Expose
    private Integer city;

    public Integer getWhen() {
        return when;
    }

    public void setWhen(Integer when) {
        this.when = when;
    }    

    public Integer getCity() {
        return city;
    }

    public void setCity(Integer city) {
        this.city = city;
    }

  }

AND

public class JsonAdded {

@SerializedName("jsondata")
@Expose
private Jsondata jsondata;

public Jsondata getJsondata() {
    return jsondata;
}

public void setJsondata(Jsondata jsondata) {
    this.jsondata = jsondata;
  }

}

Finally the call and the callback

   RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint(Constants.GET_API_URL_BASE)
                .build();
        apiGet = adapter.create(ApiCalls.class);
    Jsondata jsondata = new Jsondata();
                jsondata.setCity(1);
                jsondata.setWhen(1);

                JsonAdded jsonAdded =  newJsonAdded();
                jsonAdded.setJsondata(jsondata);

                apiGet.getConditions(jsonAdded, new Callback <List<PojoBeaches>>() {

                    @Override
                    public void success(List<PojoBeaches> pojoBeaches, Response response) {
                        Log.d(Constants.TAG,"SUCESS ");

                    }

                    @Override
                    public void failure(RetrofitError error) {
                        Log.d(Constants.TAG,"ERROR "+error.getMessage());

                    }
                });

My problem is I am getting null as error , I have been implementing other solutions but nothing work as far, always null is got.
The Log cat I get is just " ERROR null " .
Any idea?please what I am doing wrong?

Edited and added Log cat with setLogLevel(RestAdapter.LogLevel.FULL)

D/Retrofit: java.io.EOFException at libcore.io.Streams.readAsciiLine(Streams.java:203) at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560) at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813) at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486) at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73) at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38) at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326) at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220) at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278) at retrofit.CallbackRunnable.run(CallbackRunnable.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at retrofit.Platform$Android$2$1.run(Platform.java:142) at java.lang.Thread.run(Thread.java:856)

Community
  • 1
  • 1
JoCuTo
  • 2,463
  • 4
  • 28
  • 44

0 Answers0