简体   繁体   中英

Android Retrofit error HTTP method annotation is required (e.g., @GET, @POST, etc.)

I am having an issue with my Retrofit code, and I seem to be either missing something or not fully understanding what I need done. Here is a full copy of my error. I am not using ProGuard, but I did already apply all of the exceptions are you suppose to in the rules set just to make sure. Minify is set to false both for debug and release.

Is anyone able to help me figure this out, I would greatly appreciate it!

    05-01 11:08:37.967  12277-12357/com.gbp.sean.reorderscanner         E/VMIROrderService﹕ Exception Posting Order
retrofit.RetrofitError: OrderEntryInterface.update: HTTP method annotation is required (e.g., @GET, @POST, etc.).
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
        at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
        at java.lang.reflect.Proxy.invoke(Proxy.java:397)
        at $Proxy0.update(Unknown Source)
        at com.gbp.sean.reorderscanner.VMIROrderService.getEntryResult(VMIROrderService.java:65)
        at com.gbp.sean.reorderscanner.VMIROrderService.onHandleIntent(VMIROrderService.java:41)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.os.HandlerThread.run(HandlerThread.java:61)
 Caused by: java.lang.IllegalArgumentException: OrderEntryInterface.update: HTTP method annotation is required (e.g., @GET, @POST, etc.).
        at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
        at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:179)
        at retrofit.RestMethodInfo.init(RestMethodInfo.java:117)
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
        at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
        at java.lang.reflect.Proxy.invoke(Proxy.java:397)
        at $Proxy0.update(Unknown Source)
        at com.gbp.sean.reorderscanner.VMIROrderService.getEntryResult(VMIROrderService.java:65)
        at com.gbp.sean.reorderscanner.VMIROrderService.onHandleIntent(VMIROrderService.java:41)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.os.HandlerThread.run(HandlerThread.java:61)

Here is a copy of my OrderEntryInterface

 import retrofit.http.GET;
 import retrofit.http.Path;

 public interface OrderEntryInterface {

    @GET("/ServiceNameFilteredOut/json/@id={id}@ord={ord}")
    OrderDetails details(
        @Path("id") String id,
        @Path("ord") String ord
    );
    OrderInfo update();
}

And here is the important parts of my OrderService

@Override
protected void onHandleIntent(Intent intent) {
    try {
        this.id = intent.getExtras().getString("id");
        this.ord = intent.getExtras().getString("ord");
        String result=getEntryResult();

        Log.d(getClass().getSimpleName(),result);

        if(result != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), "Posted Successfully", Toast.LENGTH_LONG).show();
                }
            });
        }
    }
    catch (Exception e) {
        Log.e(getClass().getSimpleName(), "Exception Posting Order", e);
    }
}

private String getEntryResult() {
    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://WebPageURLFilteredOut/").build();
    OrderEntryInterface entryInterface = restAdapter.create(OrderEntryInterface.class);

    entryInterface.details(id,ord);

    OrderInfo info = entryInterface.update();

    if (info.PostOrderResult == "Confirmed") {
        return (info.PostOrderResult);
    }

    return (null);
}

You have an annotation on the details() method. You are calling the update() method. The error message indicates that the update() method is what is missing the annotation. And, according to your code, you do not have an annotation on the update() method.

So, add a Retrofit annotation to the update() method.

Ensure all imports are retrofit2. eg

import retrofit2.http.POST;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;

or whatever version your are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM