[英]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.