Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Retrofit: missing method body, or declare abstract

I am writing an android app that will use Retrofit to make API requests.

I have a helper class like this:

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 Retrofit implementation is simple:

public class ApiEndpointInterface {

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

The problem is, I cannot 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?

like image 976
johncorser Avatar asked Jun 09 '26 15:06

johncorser


1 Answers

Try public interface for your API declaration.

public interface ApiEndpointInterface {

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

Also, looks like you're creating your ApiEndpointInterface before telling the builder to set log level to full.

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;
}
like image 74
Zadrox Avatar answered Jun 12 '26 09:06

Zadrox