简体   繁体   English

Android Retrofit 错误 HTTP 方法注释是必需的(例如,@GET、@POST 等)

[英]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.我的 Retrofit 代码有问题,我似乎要么遗漏了什么,要么没有完全理解我需要做什么。 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.我没有使用 ProGuard,但我确实已经在规则集中应用了您认为的所有例外情况,只是为了确保。 Minify is set to false both for debug and release.对于调试和发布,Minify 都设置为 false。

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这是我的 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这是我的 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.您在details()方法上有一个注释。 You are calling the update() method.您正在调用update()方法。 The error message indicates that the update() method is what is missing the annotation.错误消息表明update()方法缺少注释。 And, according to your code, you do not have an annotation on the update() method.而且,根据您的代码,您没有关于update()方法的注释。

So, add a Retrofit annotation to the update() method.因此,向update()方法添加 Retrofit 注释。

Ensure all imports are retrofit2.确保所有进口都是改装2。 eg例如

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

or whatever version your are using.或您使用的任何版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio 显示此错误:Retrofit2 Android HTTP 方法注释是必需的(例如,@GET、@POST 等) - Android Studio showing this error :Retrofit2 Android HTTP method annotation is required (e.g., @GET, @POST, etc.) Retrofi2 Android HTTP 方法注释是必需的(例如,@GET,@POST等) - Retrofi2 Android HTTP method annotation is required (e.g., @GET, @POST, etc.) java.lang.IllegalArgumentException: HTTP 方法注释是必需的(例如,@GET、@POST 等)。尝试调用apiInterface GET 请求时出错 - java.lang.IllegalArgumentException: HTTP method annotation is required (e.g., @GET, @POST, etc.).Error when trying call apiInterface GET request 在Android上的Scala代码中改进HTTP报告“需要HTTP方法注释” - Retrofit HTTP reporting “HTTP method annotation is required” in Scala code on Android 如何在Java中查看内置类的源代码(例如BigInteger等)? - How do I view source code of built-in classes in Java (e.g. BigInteger etc.)? POST期间在REST Web服务中使用FormParam包含自己的对象(例如实体)的HTTP 400错误 - HTTP 400 error in REST web service during POST with FormParam containing own objects (e.g. enities) Method getResources没有用请求类型注释(例如,GET,POST)是什么意思? - what does Method getResources not annotated with request type (e.g., GET, POST) mean? 我们可以修改或自定义Java对象的数据结构(例如树,链表等)吗? - Can we modify or customise the data structure(for e.g. tree, Linked List etc.) of Java object(s)? 如何按等级对数组的值进行排序(例如85-100是A,70-84是B等) - How do you sort the values of arrays by grade (e.g. 85-100 is an A 70-84 is a B etc.) 使用Spring Security,我如何使用HTTP方法(例如GET,PUT,POST)来确定特定URL模式的安全性? - Using Spring Security, how can I use HTTP methods (e.g. GET, PUT, POST) to distingush security for particular URL patterns?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM