Android Retrofit: missing method body or declare abstract

I am writing an Android application that will use Retrofit to make API requests.

I have a helper class:

public class ApiService {
    public static final String TAG = ApiService.class.getSimpleName();

    public static final String BASE_URL = "https://myapiurl.com";

    public static void testApi(){
        ApiEndpointInterface apiService = prepareService();
        apiService.ping(new Callback<Response>() {
            @Override
            public void success(Response apiResponse, retrofit.client.Response response) {
                Log.e(TAG, apiResponse.toString());

            }

            @Override
            public void failure(RetrofitError error) {
                Log.e("Retrofit:", error.toString());

            }
        });

    }

    private static ApiEndpointInterface prepareService() {
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(BASE_URL)
                .build();
        ApiEndpointInterface apiService =
                restAdapter.create(ApiEndpointInterface.class);

        restAdapter.setLogLevel(RestAdapter.LogLevel.FULL);
        return apiService;
    }

}

      

And my actual implementation of the Appendix is ​​simple:

public class ApiEndpointInterface {

    @GET("/v1/myendpoint")
    void ping(Callback<Response> cb);
}

      

The problem is I can't build the project, I get the error:

Error:(12, 10) error: missing method body, or declare abstract

      

Referring to my ApiEndpointInterface class.

Any idea what's going on?

+3


source to share


2 answers


Try public interface

for your API declaration.

public interface ApiEndpointInterface {

    @GET("/v1/myendpoint")
    void ping(Callback<Response> cb);
}

      



Also, it looks like you are creating your ApiEndpointInterface before telling the builder to set the log level completely.

private static ApiEndpointInterface prepareService() {

    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(BASE_URL)
            .setLogLevel(RestAdapter.LogLevel.FULL);
            .build();

    ApiEndpointInterface apiService =
            restAdapter.create(ApiEndpointInterface.class);

    return apiService;
}

      

+10


source


If you update okHttp Version 2.4.0, you will get an empty body exception as the latest version no longer allows zero length request, in which case you will have to use the following syntax

public interface ApiEndpointInterface {

@GET("/v1/myendpoint")
void ping(Callback<Response> cb, @Body String dummy);

      

}



call

 ApiEndpointInterface apiService =
            restAdapter.create(ApiEndpointInterface.class);

 apiService.ping(callback,"");

      

Link https://github.com/square/okhttp/issues/751

+1


source







All Articles