Android Retrofit错误需要HTTP方法注释(例如,@ GET,@ POST等)

时间:2015-05-01 16:24:03

标签: java android runtime-error retrofit

我的Retrofit代码存在问题,我似乎要么缺少某些内容,要么完全不了解我需要做什么。这是我的错误的完整副本。我没有使用ProGuard,但我确实已经在规则集中应用了所有的例外情况以确保。对于调试和释放,Minify都设置为false。

是否有人能帮助我解决这个问题,我将不胜感激!

    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)

这是我的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();
}

以下是我的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);
}

1 个答案:

答案 0 :(得分:1)

确保所有进口都是改造2。 e.g

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

或您正在使用的任何版本。