Java – Android retro fit: missing method body or declaration abstraction
•
Java
I'm writing an Android application that will use retrofit to make API requests
I have such 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;
}
}
My actual retrofit implementation is simple:
public class ApiEndpointInterface {
@GET("/v1/myendpoint")
void ping(Callback<Response> cb);
}
The problem is, I can't build the project. I received an error:
Error:(12,10) error: missing method body,or declare abstract
Refer to my apiendpointinterface class
Do you know what happened?
Solution
An attempt was made to declare an API using a public interface
public interface ApiEndpointInterface {
@GET("/v1/myendpoint")
void ping(Callback<Response> cb);
}
In addition, you seem to be creating apiendpointinterface. Before telling the builder to set the 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;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
